Skip to content

Commit 288abcb

Browse files
authored
Merge pull request #41 from smurfix/master
Fix #40
2 parents 2887766 + 1083e2c commit 288abcb

3 files changed

Lines changed: 9 additions & 3 deletions

File tree

newsfragments/40.bugfix.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Defer creating an asyncio coroutine until asyncio mode is actually entered.

trio_asyncio/_version.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
# This file is imported from __init__.py and exec'd from setup.py
22

3-
__version__ = "0.9.0"
3+
__version__ = "0.9.1"

trio_asyncio/adapter.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,10 @@ def trio2aio(proc):
3535
return aio_as_trio(proc)
3636

3737

38+
async def _call_defer(proc, *args, **kwargs):
39+
return await proc(*args, **kwargs)
40+
41+
3842
class Asyncio_Trio_Wrapper:
3943
"""
4044
This wrapper object encapsulates an asyncio-style coroutine,
@@ -66,8 +70,9 @@ async def __call__(self, *args, **kwargs):
6670
if self.args:
6771
raise RuntimeError("Call 'aio_as_trio(proc)(*args)', not 'aio_as_trio(proc, *args)'")
6872

69-
# TODO: do this within the loop context
70-
f = self.proc(*args, **kwargs)
73+
# We route this through _calL_defer because some wrappers require
74+
# running in asyncio context
75+
f = _call_defer(self.proc, *args, **kwargs)
7176
return await self.loop.run_aio_coroutine(f)
7277

7378
def __await__(self):

0 commit comments

Comments
 (0)