File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -214,8 +214,12 @@ async def run_coroutine(self, coro):
214214 This is a Trio coroutine.
215215 """
216216 self ._check_closed ()
217+ t = sniffio .current_async_library_cvar .set ("asyncio" )
217218 coro = asyncio .ensure_future (coro , loop = self )
218- return await run_future (coro )
219+ try :
220+ return await run_future (coro )
221+ finally :
222+ sniffio .current_async_library_cvar .reset (t )
219223
220224 def wrap_generator (self , gen , * args ):
221225 """Call an asyncio generator.
Original file line number Diff line number Diff line change 11import sys
22import trio
33import asyncio
4+ import sniffio
45try :
56 from asyncio .format_helpers import _format_callback , _get_function_source
67except ImportError : # <3.7
@@ -17,6 +18,11 @@ def _format_callback_source(func, args):
1718 return func_repr
1819
1920
21+ async def _set_sniff (proc , * args ):
22+ sniffio .current_async_library_cvar .set ("trio" )
23+ return await proc (* args )
24+
25+
2026class _TrioHandle :
2127 """
2228 This extends asyncio.Handle by providing:
@@ -98,9 +104,9 @@ async def _call_async(self, task_status=trio.TASK_STATUS_IGNORED):
98104 with trio .open_cancel_scope () as scope :
99105 self ._scope = scope
100106 if self ._is_sync is None :
101- await self ._context .run (self ._callback , self )
107+ await self ._context .run (_set_sniff , self ._callback , self )
102108 else :
103- await self ._context .run (self ._callback , * self ._args )
109+ await self ._context .run (_set_sniff , self ._callback , * self ._args )
104110 except Exception as exc :
105111 self ._raise (exc )
106112 finally :
You can’t perform that action at this time.
0 commit comments