Commit 620691c7 authored by Denis Bilenko's avatar Denis Bilenko

hub.join(): add timeout argument

parent fac41703
...@@ -320,21 +320,28 @@ class Hub(greenlet): ...@@ -320,21 +320,28 @@ class Hub(greenlet):
# to return an unexpected value # to return an unexpected value
raise LoopExit raise LoopExit
def join(self): def join(self, timeout=None):
"""Wait for the event loop to finish. Exits only when there are """Wait for the event loop to finish. Exits only when there are
no more spawned greenlets, started servers, active timeouts or watchers. no more spawned greenlets, started servers, active timeouts or watchers.
""" """
assert getcurrent() is self.parent, "only possible from MAIN greenlet" assert getcurrent() is self.parent, "only possible from MAIN greenlet"
if not self or self.dead: if self.dead:
if _threadlocal.__dict__.get('hub') is self: return
_threadlocal.__dict__.pop('hub')
self.run = None if timeout is not None:
else: timeout = self.loop.timer(timeout)
timeout.start(getcurrent().switch)
timeout.loop.unref()
try:
try: try:
self.switch() self.switch()
except LoopExit: except LoopExit:
pass return True
self.loop.error_handler = None # break the ref cycle finally:
if timeout is not None and timeout.active:
timeout.loop.ref()
timeout.stop()
def _get_resolver(self): def _get_resolver(self):
if self._resolver is None: if self._resolver is None:
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment