Skip to content

Commit

Permalink
asyncio: Optimize _get_running_loop() to call getpid() only when ther…
Browse files Browse the repository at this point in the history
…e's a loop
  • Loading branch information
1st1 committed Mar 3, 2017
1 parent 604faba commit 2ef08d3
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions Lib/asyncio/events.py
Original file line number Diff line number Diff line change
Expand Up @@ -624,8 +624,9 @@ def _get_running_loop():
This is a low-level function intended to be used by event loops.
This function is thread-specific.
"""
if _running_loop._pid == os.getpid():
return _running_loop._loop
running_loop = _running_loop._loop
if running_loop is not None and _running_loop._pid == os.getpid():
return running_loop


def _set_running_loop(loop):
Expand Down

0 comments on commit 2ef08d3

Please sign in to comment.