From 9f21f168f1f98730b42f5eb941fca687d7015974 Mon Sep 17 00:00:00 2001 From: asrp Date: Mon, 6 Sep 2021 12:28:50 -0400 Subject: [PATCH] Make asyncio main importable by fixing references to global vars --- Lib/asyncio/__main__.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/Lib/asyncio/__main__.py b/Lib/asyncio/__main__.py index 18bb87a5bc4ffd..d8324d81b0a933 100644 --- a/Lib/asyncio/__main__.py +++ b/Lib/asyncio/__main__.py @@ -52,7 +52,7 @@ def callback(): except BaseException as exc: future.set_exception(exc) - loop.call_soon_threadsafe(callback) + self.loop.call_soon_threadsafe(callback) try: return future.result() @@ -77,7 +77,7 @@ def run(self): f'{getattr(sys, "ps1", ">>> ")}import asyncio' ) - console.interact( + self.console.interact( banner=banner, exitmsg='exiting asyncio REPL...') finally: @@ -86,7 +86,7 @@ def run(self): message=r'^coroutine .* was never awaited$', category=RuntimeWarning) - loop.call_soon_threadsafe(loop.stop) + self.loop.call_soon_threadsafe(self.loop.stop) if __name__ == '__main__': @@ -111,6 +111,8 @@ def run(self): repl_thread = REPLThread() repl_thread.daemon = True + repl_thread.loop = loop + repl_thread.console = console repl_thread.start() while True: