Skip to content

bpo-43419: fix contextvars behaviors in asyncio REPL #24773

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
Closed
Changes from all 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
5 changes: 4 additions & 1 deletion Lib/asyncio/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import threading
import types
import warnings
import contextvars

from . import futures

Expand All @@ -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
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -103,6 +105,7 @@ def run(self):

repl_future = None
repl_future_interrupted = False
repl_context = contextvars.Context()

try:
import readline # NoQA
Expand Down