Skip to content

Commit 2ef08d3

Browse files
committed
asyncio: Optimize _get_running_loop() to call getpid() only when there's a loop
1 parent 604faba commit 2ef08d3

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

Lib/asyncio/events.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -624,8 +624,9 @@ def _get_running_loop():
624624
This is a low-level function intended to be used by event loops.
625625
This function is thread-specific.
626626
"""
627-
if _running_loop._pid == os.getpid():
628-
return _running_loop._loop
627+
running_loop = _running_loop._loop
628+
if running_loop is not None and _running_loop._pid == os.getpid():
629+
return running_loop
629630

630631

631632
def _set_running_loop(loop):

0 commit comments

Comments
 (0)