Skip to content

Commit 85ad18e

Browse files
committed
keep python and c current event loop in sync
1 parent 32b17a5 commit 85ad18e

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

Lib/asyncio/events.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -768,6 +768,14 @@ def _get_running_loop():
768768
This is a low-level function intended to be used by event loops.
769769
This function is thread-specific.
770770
"""
771+
# Prefer C implementation if available
772+
try:
773+
if _c__get_running_loop is not _py__get_running_loop:
774+
return _c__get_running_loop()
775+
except NameError:
776+
# C implementation not available
777+
pass
778+
771779
# NOTE: this function is implemented in C (see _asynciomodule.c)
772780
running_loop, pid = _running_loop.loop_pid
773781
if running_loop is not None and pid == os.getpid():
@@ -782,6 +790,14 @@ def _set_running_loop(loop):
782790
"""
783791
# NOTE: this function is implemented in C (see _asynciomodule.c)
784792
_running_loop.loop_pid = (loop, os.getpid())
793+
794+
# Keep C implementation in sync if available
795+
try:
796+
if _c__set_running_loop is not _py__set_running_loop:
797+
_c__set_running_loop(loop)
798+
except NameError:
799+
# C implementation not available
800+
pass
785801

786802

787803
def _init_event_loop_policy():

0 commit comments

Comments
 (0)