summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorYury Selivanov <yury@magic.io>2017-03-02 23:57:33 -0500
committerYury Selivanov <yury@magic.io>2017-03-02 23:58:07 -0500
commit902e9c50e31209e796b6bbe26f8d2f57ec12071b (patch)
tree87748c596b63944987b1089c9e3a7bb031e22d65
parent84af903f3bc6780cb4e73ff05ad2e242d3966417 (diff)
downloadcpython-git-902e9c50e31209e796b6bbe26f8d2f57ec12071b.tar.gz
asyncio: Optimize _get_running_loop() to call getpid() only when there's a loop
-rw-r--r--Lib/asyncio/events.py5
1 files changed, 3 insertions, 2 deletions
diff --git a/Lib/asyncio/events.py b/Lib/asyncio/events.py
index 7b30b4c84a..e85634e588 100644
--- a/Lib/asyncio/events.py
+++ b/Lib/asyncio/events.py
@@ -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):