def forever(self, interval_seconds = 1, cb_interval_func = None, func_data = None): counter = 0 interval = interval_seconds * 10 while not self.is_stop(): time.sleep(0.1) counter += 1 if counter == interval: counter = 0 if cb_interval_func: try: cb_interval_func(func_data) except: util.except_print("cb_interval_func") pass pass # block wait child processes exit for pname in self.workers.keys(): self.workers[pname].join() util.warn("{}: worker stopped.".format(pname)) with self.glock: util.remove_file_nothrow(self.pidfile) util.remove_file_nothrow(self.stopfile) pass
def notify_stop(self, exitCode = 0): try: self.lock() if not util.file_exists(self.stopfile): os.mknod(self.stopfile) else: util.warn("stopfile already exists: " + self.stopfile) except: util.except_print("notify_stop") finally: try: self.unlock() except: util.except_print("unlock") pass if not exitCode is None: sys.exit(exitCode) pass