def restart(self, reason='unknown'): with self.lock: if not self.shutdown.is_set(): self.log.debug('restarting the source, reason <%s>' % (reason)) self.evq.put((cmsg(self.target, SchemaReadLock()), )) try: self.close() if self.th: self.th.join() self.start() finally: self.evq.put((cmsg(self.target, SchemaReadUnlock()), ))
def close(self): with self._global_lock: if self._dbm_shutdown.is_set(): return else: self._dbm_shutdown.set() if hasattr(atexit, 'unregister'): atexit.unregister(self.close) else: try: atexit._exithandlers.remove((self.close, (), {})) except ValueError: pass # shutdown the _dbm_thread self._event_queue.shutdown() self._event_queue.bypass((cmsg(None, ShutdownException()), )) self._dbm_thread.join()