Issue #23353, asyncio: Workaround CPython bug #23353
Don't use yield/yield-from in an except block of a generator. Store the
exception and handle it outside the except block.
diff --git a/Lib/asyncio/unix_events.py b/Lib/asyncio/unix_events.py
index 1fc39ab..75e7c9c 100644
--- a/Lib/asyncio/unix_events.py
+++ b/Lib/asyncio/unix_events.py
@@ -186,10 +186,18 @@
self._child_watcher_callback, transp)
try:
yield from waiter
- except:
+ except Exception as exc:
+ # Workaround CPython bug #23353: using yield/yield-from in an
+ # except block of a generator doesn't clear properly
+ # sys.exc_info()
+ err = exc
+ else:
+ err = None
+
+ if err is not None:
transp.close()
yield from transp._wait()
- raise
+ raise err
return transp