Skip to content

Commit d1e3403

Browse files
jimmylaiasvetlov
authored andcommitted
[asyncio] bpo-30423: add regression test for orphan future causes "RuntimeError: Event loop stopped before Future completed." (#3295)
* call remove_done_callback in finally section * [asyncio] bpo-30423 bug: add regression test for orphan future causes "RuntimeError: Event loop stopped before Future completed."
1 parent 894ebd0 commit d1e3403

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

Lib/test/test_asyncio/test_base_events.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -529,6 +529,22 @@ def test_run_until_complete_loop(self):
529529
self.assertRaises(ValueError,
530530
other_loop.run_until_complete, task)
531531

532+
def test_run_until_complete_loop_orphan_future_close_loop(self):
533+
async def foo(sec=0):
534+
await asyncio.sleep(sec)
535+
536+
self.loop.close()
537+
loop = asyncio.new_event_loop()
538+
asyncio.set_event_loop(loop)
539+
try:
540+
with mock.patch('asyncio.base_events.BaseEventLoop.run_forever',
541+
side_effect=Exception):
542+
loop.run_until_complete(foo())
543+
except:
544+
pass
545+
loop.run_until_complete(foo(0.1))
546+
loop.close()
547+
532548
def test_subprocess_exec_invalid_args(self):
533549
args = [sys.executable, '-c', 'pass']
534550

0 commit comments

Comments
 (0)