@@ -182,6 +182,7 @@ def set_event_loop(self, loop):
182
182
else :
183
183
super ().set_event_loop (loop )
184
184
185
+
185
186
# get_event_loop() without a running loop is deprecated in 3.12+. The logic for emitting the
186
187
# DeprecationWarning walks the stack looking at module names in order to associate it with
187
188
# the first caller outside asyncio. We need to pretend to be asyncio in order for that to work.
@@ -190,6 +191,7 @@ def set_event_loop(self, loop):
190
191
191
192
# Make sure we don't try to continue using the Trio loop after a fork()
192
193
if hasattr (os , "register_at_fork" ):
194
+
193
195
def _clear_state_after_fork ():
194
196
if _in_trio_context ():
195
197
from trio ._core ._run import GLOBAL_RUN_CONTEXT
@@ -240,6 +242,7 @@ def _new_policy_set(new_policy):
240
242
241
243
_orig_run_get = _aio_event ._get_running_loop
242
244
245
+
243
246
def _new_run_get ():
244
247
try :
245
248
task = trio .lowlevel .current_task ()
@@ -252,6 +255,7 @@ def _new_run_get():
252
255
# Not Trio context
253
256
return _orig_run_get ()
254
257
258
+
255
259
# Must override the non-underscore-prefixed get_running_loop() too,
256
260
# else will use the C-accelerated one which doesn't call the patched
257
261
# _get_running_loop()
@@ -261,6 +265,7 @@ def _new_run_get_or_throw():
261
265
raise RuntimeError ("no running event loop" )
262
266
return result
263
267
268
+
264
269
_aio_event ._get_running_loop = _new_run_get
265
270
_aio_event .get_running_loop = _new_run_get_or_throw
266
271
asyncio ._get_running_loop = _new_run_get
@@ -298,9 +303,11 @@ def _new_loop_new():
298
303
# accesses the non-monkeypatched version of _get_running_loop()
299
304
from asyncio import current_task as _orig_current_task
300
305
306
+
301
307
def _new_current_task (loop = None ):
302
308
return _orig_current_task (loop or _new_run_get ())
303
309
310
+
304
311
asyncio .tasks .current_task = _new_current_task
305
312
asyncio .current_task = _new_current_task
306
313
0 commit comments