def await_done(self, timeout=None): """ Await completion of connection-observer. CAUTION: if you call it from asynchronous code (async def) you may block events loop for long time. You should rather await it via: result = await connection_observer or (to have timeout) result = await asyncio.wait_for(connection_observer, timeout=10) or you may delegate blocking call execution to separate thread, see: https://pymotw.com/3/asyncio/executors.html :param timeout: :return: observer result """ if self.done(): return self.result() with exception_stored_if_not_main_thread(self): if not self.life_status._is_running: raise ConnectionObserverNotStarted(self) # check if already is running self.runner.wait_for(connection_observer=self, connection_observer_future=self._future, timeout=timeout) return self.result()
def await_done(self, timeout=10.0): """Await completion of connection-observer.""" if self.done(): return self.result() if self._future is None: raise ConnectionObserverNotStarted(self) result = self.runner.wait_for(connection_observer=self, connection_observer_future=self._future, timeout=timeout) return result
def await_done(self, timeout=None): """Await completion of connection-observer.""" if self.done(): return self.result() if not self._is_running: raise ConnectionObserverNotStarted(self) while self._future is None: time.sleep(0.005) if self.done(): break if self._future: self.runner.wait_for(connection_observer=self, connection_observer_future=self._future, timeout=timeout) return self.result()