From adc04fb4ece0f3c54da872a99ffa9829699e3a90 Mon Sep 17 00:00:00 2001 From: hetmankp <728670+hetmankp@users.noreply.github.com> Date: Tue, 4 Oct 2022 00:58:54 +1100 Subject: [PATCH] gh-94732: Fix KeyboardInterrupt race in asyncio run_forever() This addresses issue #94732, ensuring 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. --- Lib/asyncio/base_events.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/Lib/asyncio/base_events.py b/Lib/asyncio/base_events.py index 2df9dcac8f723f..66202f09794db8 100644 --- a/Lib/asyncio/base_events.py +++ b/Lib/asyncio/base_events.py @@ -606,12 +606,13 @@ def run_forever(self): 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() pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy