Skip to content
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

Add support for sniffio #278

Closed
wants to merge 1 commit 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
15 changes: 13 additions & 2 deletions curio/kernel.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,11 @@
from .timequeue import TimeQueue
from .activation import Activation

try:
from sniffio import current_async_library_cvar
except ImportError:
current_async_library_cvar = None

# ----------------------------------------------------------------------
# Underlying kernel that drives everything
# ----------------------------------------------------------------------
Expand Down Expand Up @@ -823,5 +828,11 @@ def run(corofunc, *args, with_monitor=False, selector=None,
m = Monitor(kernel)
kernel._call_at_shutdown(m.close)

with kernel:
return kernel.run(corofunc, *args)
if current_async_library_cvar is not None:
token = current_async_library_cvar.set("curio")
try:
with kernel:
return kernel.run(corofunc, *args)
finally:
if current_async_library_cvar is not None:
current_async_library_cvar.reset(token)