There is a race with the KeyboardInterrupt exception in the asyncio.base_events.BaseEventLoop.run_forever() method. While an attempt is made to restore the environment to its previous state before run_forever() completes with a try...finally, a couple items find themselves outside the try...finally. Specifically, a badly timed KeyboardInterrupt will mean that, neither the self._thread_id value or the hooks set by sys.set_asyncgen_hooks() will be correctly restored. Both of these should be moved inside the try...finally.
| 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) |
This applies to all existing version of Python on all platforms.
There is a race with the
KeyboardInterruptexception in the asyncio.base_events.BaseEventLoop.run_forever() method. While an attempt is made to restore the environment to its previous state beforerun_forever()completes with atry...finally, a couple items find themselves outside thetry...finally. Specifically, a badly timedKeyboardInterruptwill mean that, neither theself._thread_idvalue or the hooks set bysys.set_asyncgen_hooks()will be correctly restored. Both of these should be moved inside thetry...finally.cpython/Lib/asyncio/base_events.py
Lines 596 to 600 in c9118af
This applies to all existing version of Python on all platforms.