summaryrefslogtreecommitdiff
path: root/Lib/asyncio
diff options
context:
space:
mode:
authorYury Selivanov <yury@magic.io>2016-09-15 13:24:03 -0400
committerYury Selivanov <yury@magic.io>2016-09-15 13:24:03 -0400
commit7ae56e9058eb9fc24a8d203f913be6e8ae7e6823 (patch)
treec008cc1e41384748c2f908f6a601ec32965b9c62 /Lib/asyncio
parent75a546e4742311e7ed442e47410c55e57de71fd6 (diff)
downloadcpython-7ae56e9058eb9fc24a8d203f913be6e8ae7e6823.tar.gz
Merge 3.5 (asyncio)
Diffstat (limited to 'Lib/asyncio')
-rw-r--r--Lib/asyncio/base_events.py24
1 files changed, 16 insertions, 8 deletions
diff --git a/Lib/asyncio/base_events.py b/Lib/asyncio/base_events.py
index 9c2fa12486..154fd95513 100644
--- a/Lib/asyncio/base_events.py
+++ b/Lib/asyncio/base_events.py
@@ -242,9 +242,13 @@ class BaseEventLoop(events.AbstractEventLoop):
self._task_factory = None
self._coroutine_wrapper_set = False
- # A weak set of all asynchronous generators that are being iterated
- # by the loop.
- self._asyncgens = weakref.WeakSet()
+ if hasattr(sys, 'get_asyncgen_hooks'):
+ # Python >= 3.6
+ # A weak set of all asynchronous generators that are
+ # being iterated by the loop.
+ self._asyncgens = weakref.WeakSet()
+ else:
+ self._asyncgens = None
# Set to True when `loop.shutdown_asyncgens` is called.
self._asyncgens_shutdown_called = False
@@ -359,7 +363,9 @@ class BaseEventLoop(events.AbstractEventLoop):
"""Shutdown all active asynchronous generators."""
self._asyncgens_shutdown_called = True
- if not len(self._asyncgens):
+ if self._asyncgens is None or not len(self._asyncgens):
+ # If Python version is <3.6 or we don't have any asynchronous
+ # generators alive.
return
closing_agens = list(self._asyncgens)
@@ -387,9 +393,10 @@ class BaseEventLoop(events.AbstractEventLoop):
raise RuntimeError('Event loop is running.')
self._set_coroutine_wrapper(self._debug)
self._thread_id = threading.get_ident()
- old_agen_hooks = sys.get_asyncgen_hooks()
- sys.set_asyncgen_hooks(firstiter=self._asyncgen_firstiter_hook,
- finalizer=self._asyncgen_finalizer_hook)
+ if self._asyncgens is not None:
+ old_agen_hooks = sys.get_asyncgen_hooks()
+ sys.set_asyncgen_hooks(firstiter=self._asyncgen_firstiter_hook,
+ finalizer=self._asyncgen_finalizer_hook)
try:
while True:
self._run_once()
@@ -399,7 +406,8 @@ class BaseEventLoop(events.AbstractEventLoop):
self._stopping = False
self._thread_id = None
self._set_coroutine_wrapper(False)
- sys.set_asyncgen_hooks(*old_agen_hooks)
+ if self._asyncgens is not None:
+ sys.set_asyncgen_hooks(*old_agen_hooks)
def run_until_complete(self, future):
"""Run until the Future is done.