Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions Lib/asyncio/runners.py
Original file line number Diff line number Diff line change
Expand Up @@ -176,8 +176,12 @@ async def main():
raise RuntimeError(
"asyncio.run() cannot be called from a running event loop")

with Runner(debug=debug) as runner:
return runner.run(main)
try:
with Runner(debug=debug) as runner:
events.set_event_loop(runner.get_loop())
return runner.run(main)
finally:
events.set_event_loop(None)
Comment thread
kumaraditya303 marked this conversation as resolved.
Outdated


def _cancel_all_tasks(loop):
Expand Down
1 change: 1 addition & 0 deletions Lib/unittest/async_case.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ def _callMaybeAsync(self, func, /, *args, **kwargs):
def _setupAsyncioRunner(self):
assert self._asyncioRunner is None, 'asyncio runner is already initialized'
runner = asyncio.Runner(debug=True)
asyncio.set_event_loop(runner.get_loop())
self._asyncioRunner = runner

def _tearDownAsyncioRunner(self):
Comment thread
kumaraditya303 marked this conversation as resolved.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix :func:`asyncio.run` and :class:`unittest.IsolatedAsyncioTestCase` to always the set event loop as it was done in Python 3.10 and earlier. Patch by Kumar Aditya.