Commit 5d44c08f authored by Victor Stinner's avatar Victor Stinner

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.
parent 7a66fc22
...@@ -416,6 +416,10 @@ class TestCase(unittest.TestCase): ...@@ -416,6 +416,10 @@ class TestCase(unittest.TestCase):
def tearDown(self): def tearDown(self):
events.set_event_loop(None) events.set_event_loop(None)
# Detect CPython bug #23353: ensure that yield/yield-from is not used
# in an except block of a generator
self.assertEqual(sys.exc_info(), (None, None, None))
@contextlib.contextmanager @contextlib.contextmanager
def disable_logger(): def disable_logger():
......
...@@ -186,10 +186,18 @@ class _UnixSelectorEventLoop(selector_events.BaseSelectorEventLoop): ...@@ -186,10 +186,18 @@ class _UnixSelectorEventLoop(selector_events.BaseSelectorEventLoop):
self._child_watcher_callback, transp) self._child_watcher_callback, transp)
try: try:
yield from waiter 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() transp.close()
yield from transp._wait() yield from transp._wait()
raise raise err
return transp return transp
......
...@@ -373,10 +373,17 @@ class ProactorEventLoop(proactor_events.BaseProactorEventLoop): ...@@ -373,10 +373,17 @@ class ProactorEventLoop(proactor_events.BaseProactorEventLoop):
**kwargs) **kwargs)
try: try:
yield from waiter 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() transp.close()
yield from transp._wait() yield from transp._wait()
raise raise err
return transp return transp
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment