From: Yury Selivanov Date: Fri, 3 Mar 2017 04:57:33 +0000 (-0500) Subject: asyncio: Optimize _get_running_loop() to call getpid() only when there's a loop X-Git-Tag: v3.5.4rc1~312 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=80fbacc9369c07daeea6a50a61d214820bb29874;p=python asyncio: Optimize _get_running_loop() to call getpid() only when there's a loop --- 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):