aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/Lib/asyncio/__main__.py
diff options
context:
space:
mode:
Diffstat (limited to 'Lib/asyncio/__main__.py')
-rw-r--r--Lib/asyncio/__main__.py6
1 files changed, 4 insertions, 2 deletions
diff --git a/Lib/asyncio/__main__.py b/Lib/asyncio/__main__.py
index 5120140e061..95c636f9e02 100644
--- a/Lib/asyncio/__main__.py
+++ b/Lib/asyncio/__main__.py
@@ -1,6 +1,7 @@
import ast
import asyncio
import concurrent.futures
+import contextvars
import inspect
import os
import site
@@ -22,6 +23,7 @@ class AsyncIOInteractiveConsole(InteractiveColoredConsole):
self.compile.compiler.flags |= ast.PyCF_ALLOW_TOP_LEVEL_AWAIT
self.loop = loop
+ self.context = contextvars.copy_context()
def runcode(self, code):
global return_code
@@ -55,12 +57,12 @@ class AsyncIOInteractiveConsole(InteractiveColoredConsole):
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()