summaryrefslogtreecommitdiffstats
path: root/Lib/asyncio
diff options
context:
space:
mode:
authorjimmylai <albert_chs@yahoo.com.tw>2017-09-06 00:36:59 (GMT)
committerYury Selivanov <yury@magic.io>2017-09-06 00:36:59 (GMT)
commit80bbe6a7b67f33d0d0976bb8e3e5ba26b6b0e626 (patch)
tree5cc98acac9962d968e78e0a573b14ff61e09e481 /Lib/asyncio
parent305e56c27afce605e5d2f71903a966cf0bb95038 (diff)
downloadcpython-80bbe6a7b67f33d0d0976bb8e3e5ba26b6b0e626.zip
cpython-80bbe6a7b67f33d0d0976bb8e3e5ba26b6b0e626.tar.gz
cpython-80bbe6a7b67f33d0d0976bb8e3e5ba26b6b0e626.tar.bz2
bpo-31350: Optimize get_event_loop and _get_running_loop (#3347)
* call remove_done_callback in finally section * Optimize get_event_loop and _get_running_loop * rename _loop_pid as loop_pid and add blurb news * rename _loop_pid as loop_pid and add blurb news * add back _RunningLoop * Update 2017-09-05-10-30-48.bpo-31350.dXJ-7N.rst * Update 2017-09-05-10-30-48.bpo-31350.dXJ-7N.rst
Diffstat (limited to 'Lib/asyncio')
-rw-r--r--Lib/asyncio/events.py10
1 files changed, 4 insertions, 6 deletions
diff --git a/Lib/asyncio/events.py b/Lib/asyncio/events.py
index 6af9137..03af699 100644
--- a/Lib/asyncio/events.py
+++ b/Lib/asyncio/events.py
@@ -606,8 +606,7 @@ _lock = threading.Lock()
# A TLS for the running event loop, used by _get_running_loop.
class _RunningLoop(threading.local):
- _loop = None
- _pid = None
+ loop_pid = (None, None)
_running_loop = _RunningLoop()
@@ -619,8 +618,8 @@ def _get_running_loop():
This is a low-level function intended to be used by event loops.
This function is thread-specific.
"""
- running_loop = _running_loop._loop
- if running_loop is not None and _running_loop._pid == os.getpid():
+ running_loop, pid = _running_loop.loop_pid
+ if running_loop is not None and pid == os.getpid():
return running_loop
@@ -630,8 +629,7 @@ def _set_running_loop(loop):
This is a low-level function intended to be used by event loops.
This function is thread-specific.
"""
- _running_loop._pid = os.getpid()
- _running_loop._loop = loop
+ _running_loop.loop_pid = (loop, os.getpid())
def _init_event_loop_policy():