summaryrefslogtreecommitdiffstats
path: root/Lib
diff options
context:
space:
mode:
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>2022-10-03 21:39:44 (GMT)
committerGitHub <noreply@github.com>2022-10-03 21:39:44 (GMT)
commita7e281150e9d4ad04f4b7276eb25870a0d37fbda (patch)
tree2014f50a4cfdb79d881c0a6657d70a6a38fb0beb /Lib
parent769b9dccd2f796ffd0a75c1d088f2023c3ca28f7 (diff)
downloadcpython-a7e281150e9d4ad04f4b7276eb25870a0d37fbda.zip
cpython-a7e281150e9d4ad04f4b7276eb25870a0d37fbda.tar.gz
cpython-a7e281150e9d4ad04f4b7276eb25870a0d37fbda.tar.bz2
gh-94732: Fix KeyboardInterrupt race in asyncio run_forever() (GH-97765)
Ensure that the event loop's `_thread_id` attribute and the asyncgen hooks set by `sys.set_asyncgen_hooks()` are always restored no matter where a KeyboardInterrupt exception is raised. (cherry picked from commit 3a49dbb98ccc1b90554ed181386316efa38adfba) Co-authored-by: hetmankp <728670+hetmankp@users.noreply.github.com>
Diffstat (limited to 'Lib')
-rw-r--r--Lib/asyncio/base_events.py7
1 files changed, 4 insertions, 3 deletions
diff --git a/Lib/asyncio/base_events.py b/Lib/asyncio/base_events.py
index 1cc26ee..2384985 100644
--- a/Lib/asyncio/base_events.py
+++ b/Lib/asyncio/base_events.py
@@ -591,12 +591,13 @@ class BaseEventLoop(events.AbstractEventLoop):
self._check_closed()
self._check_running()
self._set_coroutine_origin_tracking(self._debug)
- self._thread_id = threading.get_ident()
old_agen_hooks = sys.get_asyncgen_hooks()
- sys.set_asyncgen_hooks(firstiter=self._asyncgen_firstiter_hook,
- finalizer=self._asyncgen_finalizer_hook)
try:
+ self._thread_id = threading.get_ident()
+ sys.set_asyncgen_hooks(firstiter=self._asyncgen_firstiter_hook,
+ finalizer=self._asyncgen_finalizer_hook)
+
events._set_running_loop(self)
while True:
self._run_once()