Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 3a49dbb

Browse filesBrowse files
authored
gh-94732: Fix KeyboardInterrupt race in asyncio run_forever() (#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.
1 parent 873a2f2 commit 3a49dbb
Copy full SHA for 3a49dbb

File tree

Expand file treeCollapse file tree

1 file changed

+4
-3
lines changed
Filter options
Expand file treeCollapse file tree

1 file changed

+4
-3
lines changed

‎Lib/asyncio/base_events.py

Copy file name to clipboardExpand all lines: Lib/asyncio/base_events.py
+4-3Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -606,12 +606,13 @@ def run_forever(self):
606606
self._check_closed()
607607
self._check_running()
608608
self._set_coroutine_origin_tracking(self._debug)
609-
self._thread_id = threading.get_ident()
610609

611610
old_agen_hooks = sys.get_asyncgen_hooks()
612-
sys.set_asyncgen_hooks(firstiter=self._asyncgen_firstiter_hook,
613-
finalizer=self._asyncgen_finalizer_hook)
614611
try:
612+
self._thread_id = threading.get_ident()
613+
sys.set_asyncgen_hooks(firstiter=self._asyncgen_firstiter_hook,
614+
finalizer=self._asyncgen_finalizer_hook)
615+
615616
events._set_running_loop(self)
616617
while True:
617618
self._run_once()

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.