diff options
Diffstat (limited to 'contrib/tools/python3/Lib/asyncio/__main__.py')
-rw-r--r-- | contrib/tools/python3/Lib/asyncio/__main__.py | 6 |
1 files changed, 4 insertions, 2 deletions
diff --git a/contrib/tools/python3/Lib/asyncio/__main__.py b/contrib/tools/python3/Lib/asyncio/__main__.py index 0465580115..29e528aeed 100644 --- a/contrib/tools/python3/Lib/asyncio/__main__.py +++ b/contrib/tools/python3/Lib/asyncio/__main__.py @@ -2,6 +2,7 @@ import ast import asyncio import code import concurrent.futures +import contextvars import inspect import sys import threading @@ -17,6 +18,7 @@ class AsyncIOInteractiveConsole(code.InteractiveConsole): super().__init__(locals) self.compile.compiler.flags |= ast.PyCF_ALLOW_TOP_LEVEL_AWAIT self.loop = loop + self.context = contextvars.copy_context() def runcode(self, code): future = concurrent.futures.Future() @@ -46,12 +48,12 @@ class AsyncIOInteractiveConsole(code.InteractiveConsole): return try: - repl_future = self.loop.create_task(coro) + repl_future = self.loop.create_task(coro, context=self.context) futures._chain_future(repl_future, future) except BaseException as exc: future.set_exception(exc) - loop.call_soon_threadsafe(callback) + loop.call_soon_threadsafe(callback, context=self.context) try: return future.result() |