diff --git a/Lib/asyncio/__main__.py b/Lib/asyncio/__main__.py index 18bb87a5bc4ffd..347a08a2962602 100644 --- a/Lib/asyncio/__main__.py +++ b/Lib/asyncio/__main__.py @@ -7,6 +7,7 @@ import threading import types import warnings +import contextvars from . import futures @@ -25,6 +26,7 @@ def runcode(self, code): def callback(): global repl_future global repl_future_interrupted + global repl_context repl_future = None repl_future_interrupted = False @@ -52,7 +54,7 @@ def callback(): except BaseException as exc: future.set_exception(exc) - loop.call_soon_threadsafe(callback) + loop.call_soon_threadsafe(callback, context=repl_context) try: return future.result() @@ -103,6 +105,7 @@ def run(self): repl_future = None repl_future_interrupted = False + repl_context = contextvars.Context() try: import readline # NoQA