Skip to content

Commit f97b8c7

Browse files
committed
Add test for detection in sync callback
1 parent 07c2df7 commit f97b8c7

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

sniffio/_tests/test_sniffio.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,29 @@ async def this_is_asyncio():
5858
current_async_library()
5959

6060

61+
def test_in_call_soon_threadsafe():
62+
import asyncio
63+
64+
asynclib = None
65+
completed = asyncio.Event()
66+
67+
def sync_in_loop():
68+
nonlocal asynclib
69+
try:
70+
asynclib = current_async_library()
71+
finally:
72+
completed.set()
73+
74+
async def async_in_loop():
75+
completed.wait()
76+
77+
loop = asyncio.new_event_loop()
78+
handle = loop.call_soon_threadsafe(sync_in_loop)
79+
loop.run_until_complete(async_in_loop())
80+
81+
assert asynclib == 'asyncio'
82+
83+
6184
# https://github.com/dabeaz/curio/pull/354
6285
@pytest.mark.skipif(
6386
os.name == "nt" and sys.version_info >= (3, 9),

0 commit comments

Comments
 (0)