summaryrefslogtreecommitdiffstats
path: root/Lib/asyncio
diff options
context:
space:
mode:
authorYury Selivanov <yury@magic.io>2017-12-11 15:07:44 (GMT)
committerGitHub <noreply@github.com>2017-12-11 15:07:44 (GMT)
commitabae67ebc2897ca37df067f322d19e19d1ef6d88 (patch)
tree065b5ae2fbb3a206f7b337d3a8ae8b83b566f3c1 /Lib/asyncio
parent3e9751819ad13a965e8be13c1e5bc5a6811fe6b8 (diff)
downloadcpython-abae67ebc2897ca37df067f322d19e19d1ef6d88.zip
cpython-abae67ebc2897ca37df067f322d19e19d1ef6d88.tar.gz
cpython-abae67ebc2897ca37df067f322d19e19d1ef6d88.tar.bz2
Add asyncio.get_running_loop() function. (#4782)
Diffstat (limited to 'Lib/asyncio')
-rw-r--r--Lib/asyncio/events.py14
1 files changed, 13 insertions, 1 deletions
diff --git a/Lib/asyncio/events.py b/Lib/asyncio/events.py
index 7db1ded..e425b06 100644
--- a/Lib/asyncio/events.py
+++ b/Lib/asyncio/events.py
@@ -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.