Skip to content

Commit b93c320

Browse files
authored
Merge pull request #99 from niklasf/get-running-loop
Fix asyncio.get_running_loop() monkey-patching (#83)
2 parents 9451387 + ebf62ac commit b93c320

File tree

3 files changed

+15
-0
lines changed

3 files changed

+15
-0
lines changed

Diff for: newsfragments/99.bugfix.rst

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
:func:`asyncio.get_running_loop()` will now return the trio-asyncio event loop
2+
(if running), instead of failing with :exc:`RuntimeError`.

Diff for: tests/test_trio_asyncio.py

+11
Original file line numberDiff line numberDiff line change
@@ -36,3 +36,14 @@ async def test_half_fixtured_asyncpg_conn(asyncio_fixture_own_loop):
3636
@pytest.mark.trio
3737
async def test_fixtured_asyncpg_conn(asyncio_fixture_with_fixtured_loop):
3838
await use_asyncio()
39+
40+
41+
@pytest.mark.trio
42+
async def test_get_running_loop():
43+
async with trio_asyncio.open_loop() as loop:
44+
try:
45+
from asyncio import get_running_loop
46+
except ImportError:
47+
pass # Python 3.6
48+
else:
49+
assert get_running_loop() == loop

Diff for: trio_asyncio/_loop.py

+2
Original file line numberDiff line numberDiff line change
@@ -251,6 +251,8 @@ def _new_run_get_or_throw():
251251

252252
_aio_event._get_running_loop = _new_run_get
253253
_aio_event.get_running_loop = _new_run_get_or_throw
254+
asyncio._get_running_loop = _new_run_get
255+
asyncio.get_running_loop = _new_run_get_or_throw
254256

255257
#####
256258

0 commit comments

Comments
 (0)