mirror of
https://github.com/python/cpython.git
synced 2025-11-26 13:22:51 +00:00
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.
This commit is contained in:
parent
873a2f2527
commit
3a49dbb98c
1 changed files with 4 additions and 3 deletions
|
|
@ -606,12 +606,13 @@ class BaseEventLoop(events.AbstractEventLoop):
|
||||||
self._check_closed()
|
self._check_closed()
|
||||||
self._check_running()
|
self._check_running()
|
||||||
self._set_coroutine_origin_tracking(self._debug)
|
self._set_coroutine_origin_tracking(self._debug)
|
||||||
self._thread_id = threading.get_ident()
|
|
||||||
|
|
||||||
old_agen_hooks = sys.get_asyncgen_hooks()
|
old_agen_hooks = sys.get_asyncgen_hooks()
|
||||||
sys.set_asyncgen_hooks(firstiter=self._asyncgen_firstiter_hook,
|
|
||||||
finalizer=self._asyncgen_finalizer_hook)
|
|
||||||
try:
|
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)
|
events._set_running_loop(self)
|
||||||
while True:
|
while True:
|
||||||
self._run_once()
|
self._run_once()
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue