Add asyncio.get_running_loop() function. (#4782)

This commit is contained in:
Yury Selivanov 2017-12-11 10:07:44 -05:00 committed by GitHub
parent 3e9751819a
commit abae67ebc2
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 27 additions and 1 deletions

View file

@ -7,7 +7,8 @@ __all__ = (
'get_event_loop_policy', 'set_event_loop_policy',
'get_event_loop', 'set_event_loop', 'new_event_loop',
'get_child_watcher', 'set_child_watcher',
'_set_running_loop', '_get_running_loop',
'_set_running_loop', 'get_running_loop',
'_get_running_loop',
)
import functools
@ -646,6 +647,17 @@ class _RunningLoop(threading.local):
_running_loop = _RunningLoop()
def get_running_loop():
"""Return the running event loop. Raise a RuntimeError if there is none.
This function is thread-specific.
"""
loop = _get_running_loop()
if loop is None:
raise RuntimeError('no running event loop')
return loop
def _get_running_loop():
"""Return the running event loop or None.