diff options
author | Miss Islington (bot) <31488909+miss-islington@users.noreply.github.com> | 2017-09-06 03:05:35 (GMT) |
---|---|---|
committer | Mariatta <Mariatta@users.noreply.github.com> | 2017-09-06 03:05:35 (GMT) |
commit | ff125e1aa9ee4eb928de79320a0e7c1b0c0f58f4 (patch) | |
tree | 8a4ee9a141c44d73581b4d3548fcacda75722f08 | |
parent | 11453524ed26ee449275c32bedfd86ef19dd91ee (diff) | |
download | cpython-ff125e1aa9ee4eb928de79320a0e7c1b0c0f58f4.zip cpython-ff125e1aa9ee4eb928de79320a0e7c1b0c0f58f4.tar.gz cpython-ff125e1aa9ee4eb928de79320a0e7c1b0c0f58f4.tar.bz2 |
bpo-31350: Optimize get_event_loop and _get_running_loop (GH-3347) (GH-3373)
* 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
(cherry picked from commit 80bbe6a7b67f33d0d0976bb8e3e5ba26b6b0e626)
-rw-r--r-- | Lib/asyncio/events.py | 10 | ||||
-rw-r--r-- | Misc/NEWS.d/next/Library/2017-09-05-10-30-48.bpo-31350.dXJ-7N.rst | 1 |
2 files changed, 5 insertions, 6 deletions
diff --git a/Lib/asyncio/events.py b/Lib/asyncio/events.py index e85634e..d41f3f5 100644 --- a/Lib/asyncio/events.py +++ b/Lib/asyncio/events.py @@ -611,8 +611,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() @@ -624,8 +623,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 @@ -635,8 +634,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(): diff --git a/Misc/NEWS.d/next/Library/2017-09-05-10-30-48.bpo-31350.dXJ-7N.rst b/Misc/NEWS.d/next/Library/2017-09-05-10-30-48.bpo-31350.dXJ-7N.rst new file mode 100644 index 0000000..299cf3c --- /dev/null +++ b/Misc/NEWS.d/next/Library/2017-09-05-10-30-48.bpo-31350.dXJ-7N.rst @@ -0,0 +1 @@ +Micro-optimize :func:`asyncio._get_running_loop` to become up to 10% faster. |