File tree Expand file tree Collapse file tree 2 files changed +5
-6
lines changed Expand file tree Collapse file tree 2 files changed +5
-6
lines changed Original file line number Diff line number Diff line change @@ -611,8 +611,7 @@ def new_event_loop(self):
611
611
612
612
# A TLS for the running event loop, used by _get_running_loop.
613
613
class _RunningLoop (threading .local ):
614
- _loop = None
615
- _pid = None
614
+ loop_pid = (None , None )
616
615
617
616
618
617
_running_loop = _RunningLoop ()
@@ -624,8 +623,8 @@ def _get_running_loop():
624
623
This is a low-level function intended to be used by event loops.
625
624
This function is thread-specific.
626
625
"""
627
- running_loop = _running_loop ._loop
628
- if running_loop is not None and _running_loop . _pid == os .getpid ():
626
+ running_loop , pid = _running_loop .loop_pid
627
+ if running_loop is not None and pid == os .getpid ():
629
628
return running_loop
630
629
631
630
@@ -635,8 +634,7 @@ def _set_running_loop(loop):
635
634
This is a low-level function intended to be used by event loops.
636
635
This function is thread-specific.
637
636
"""
638
- _running_loop ._pid = os .getpid ()
639
- _running_loop ._loop = loop
637
+ _running_loop .loop_pid = (loop , os .getpid ())
640
638
641
639
642
640
def _init_event_loop_policy ():
Original file line number Diff line number Diff line change
1
+ Micro-optimize :func: `asyncio._get_running_loop ` to become up to 10% faster.
You can’t perform that action at this time.
0 commit comments