8000 Workaround CPython bug #23353 · python/asyncio@aeb1824 · GitHub
[go: up one dir, main page]

Skip to content
This repository was archived by the owner on Nov 23, 2017. It is now read-only.

Commit aeb1824

Browse files
committed
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.
1 parent eec5196 commit aeb1824

File tree

3 files changed

+23
-4
lines changed

3 files changed

+23
-4
lines changed

asyncio/test_utils.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -416,6 +416,10 @@ def new_test_loop(self, gen=None):
416416
def tearDown(self):
417417
events.set_event_loop(None)
418418

419+
# Detect CPython bug #23353: ensure that yield/yield-from is not used
420+
# in an except block of a generator
421+
self.assertEqual(sys.exc_info(), (None, None, None))
422+
419423

420424
@contextlib.contextmanager
421425
def disable_logger():

asyncio/unix_events.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -186,10 +186,18 @@ def _make_subprocess_transport(self, protocol, args, shell,
186186
self._child_watcher_callback, transp)
187187
try:
188188
yield from waiter
189-
except:
189+
except Exception as exc:
190+
# Workaround CPython bug #23353: using yield/yield-from in an
191+
# except block of a generator doesn't clear properly
192+
# sys.exc_info()
193+
err = exc
194+
else:
195+
err = None
196+
197+
if err is not None:
190198
transp.close()
191199
yield from transp._wait()
192-
raise
200+
raise err
193201

194202
return transp
195203

asyncio/windows_events.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -373,10 +373,17 @@ def _make_subprocess_transport(self, protocol, args, shell,
373373
**kwargs)
374374
try:
375375
yield from waiter
376-
except:
376+
except Exception as exc:
377+
# Workaround CPython bug #23353: using yield/yield-from in an
378+
# except block of a generator doesn't clear properly sys.exc_info()
379+
err = exc
380+
else:
381+
err = None
382+
383+
if err is not None:
377384
transp.close()
378385
yield from transp._wait()
379-
raise
386+
raise err
380387

381388
return transp
382389

0 commit comments

Comments
 (0)
0