New GitHub issue #94732 from hetmankp:<br>

<hr>

<pre>
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`.

https://github.com/python/cpython/blob/c9118afd045a64ca22d4a8cc5d43532607083b2d/Lib/asyncio/base_events.py#L596-L600

This applies to all existing version of Python on all platforms.
</pre>

<hr>

<a href="https://github.com/python/cpython/issues/94732">View on GitHub</a>
<p>Labels: type-bug</p>
<p>Assignee: </p>