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 84af903 commit 902e9c5
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

1 comment on commit 902e9c5

@1st1
Copy link
Member Author

@1st1 1st1 commented on 902e9c5 Mar 3, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Related to #404.

Please sign in to comment.