def reg(self) -> float: logging.debug('Still waiting') if self.exit_in and time_now() > self.exit_in: raise TerminationException('Finished') return 1.
def tick(self) -> float: if (time_now() - self.started).total_seconds() > self.timeout: raise TimeoutError('Timeout') if all([self.has_replied_b, self.has_replied_a]): raise TerminationException() return 0.5
def broadcast(self) -> float: for x in self.origins: c = service(BroadcastClientRPC, x) c.ping() for k in list(self.origins.keys()): self.origins[k] -= 1 if self.origins[k] <= 0: del self.origins[k] logging.getLogger(__name__ + '.' + self.__class__.__name__).info( f'%d %s %s', len(self.origins_met), self.origins_met, self.origins) if len(self.origins_met) == 1 and len(self.origins) == 0: raise TerminationException() return 0.05
def exit(self): self.has_terminated = True for wfpid in self.workers_fork_addrs.values(): os.kill(wfpid, SIGTERM) while len(self.workers_free): wid = self.workers_free.pop() wpid = self.worker_addrs[wid] del self.worker_addrs[wid] os.kill(wpid, SIGKILL) self._evict_all(terminating=True) try: s = service(Broker[self.cls_req, self.cls_res], self.url_broker, ClientConfig(timeout_total=1.)) s.bk_unregister() except TimeoutError: logging.getLogger('exit').error('Could not contact broker') raise TerminationException()
def exit(self): raise TerminationException()
def ping(self): self.pings_remaining -= 1 logging.getLogger(__name__ + '.' + self.__class__.__name__).info(f'%d', self.pings_remaining) if self.pings_remaining <= 0: raise TerminationException()
def on_exit(self) -> bool: # return True if we'd like to actually exit. # todo: save the relevant local state here. raise TerminationException()
def exit_checket(self) -> float: if self.should_exit: raise TerminationException() return 1
def check_started(self): raise TerminationException()
def exc(self, exc: ConnectionAbortedError) -> bool: raise TerminationException()
def bk_exc(self, exc: ConnectionAbortedError) -> bool: trc().error('Lost connection to the worker thread') raise TerminationException()
def finished_b(self, jid: RPCKey, jres: Response): trc('1').warning('Finished %s', self.exit_in) self._ack(jid) raise TerminationException('Finished')
def stopper(self): raise TerminationException()