]> granicus.if.org Git - python/commitdiff
asyncio: Optimize _get_running_loop() to call getpid() only when there's a loop
authorYury Selivanov <yury@magic.io>
Fri, 3 Mar 2017 04:57:33 +0000 (23:57 -0500)
committerYury Selivanov <yury@magic.io>
Fri, 3 Mar 2017 04:58:07 +0000 (23:58 -0500)
Lib/asyncio/events.py

index 7b30b4c84ad9a79fb5fcb2a64baefc5f75573526..e85634e588f5a5fc88d1e03608e1fdf9d22347a6 100644 (file)
@@ -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):