Skip to content
This repository was archived by the owner on Nov 23, 2017. It is now read-only.

Commit 8e8416f

Browse files
committed
Expose _get_running_loop() and _set_running_loop() functions
Although they are prefixed with an underscore, these functions are a part of asyncio API. They will be used by third-party event loops to enable proper behaviour of get_event_loop().
1 parent ae82bb7 commit 8e8416f

File tree

2 files changed

+5
-0
lines changed

2 files changed

+5
-0
lines changed

asyncio/events.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
'get_event_loop_policy', 'set_event_loop_policy',
77
'get_event_loop', 'set_event_loop', 'new_event_loop',
88
'get_child_watcher', 'set_child_watcher',
9+
'_set_running_loop', '_get_running_loop',
910
]
1011

1112
import functools

tests/test_events.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2732,16 +2732,20 @@ def get_event_loop(self):
27322732
try:
27332733
asyncio.set_event_loop_policy(Policy())
27342734
loop = asyncio.new_event_loop()
2735+
self.assertIs(asyncio._get_running_loop(), None)
27352736

27362737
async def func():
27372738
self.assertIs(asyncio.get_event_loop(), loop)
2739+
self.assertIs(asyncio._get_running_loop(), loop)
27382740

27392741
loop.run_until_complete(func())
27402742
finally:
27412743
asyncio.set_event_loop_policy(old_policy)
27422744
if loop is not None:
27432745
loop.close()
27442746

2747+
self.assertIs(asyncio._get_running_loop(), None)
2748+
27452749

27462750
if __name__ == '__main__':
27472751
unittest.main()

0 commit comments

Comments
 (0)