def __init__(self, logger): if not _Log: _delayed_imports() if not isinstance(logger, TextLog): _Log.error("Expecting a TextLog") self.queue = _Queue("Queue for " + self.__class__.__name__, max=10000, silent=True, allow_add_after_close=True) self.logger = logger def worker(logger, please_stop): try: while not please_stop: _Till(seconds=1).wait() logs = self.queue.pop_all() for log in logs: if log is _Thread.STOP: please_stop.go() else: logger.write(**log) finally: logger.stop() self.thread = _Thread("Thread for " + self.__class__.__name__, worker, logger) self.thread.parent.remove_child(self.thread) # LOGGING WILL BE RESPONSIBLE FOR THREAD stop() self.thread.start()
def __init__(self, logger): if not _Log: _delayed_imports() self.queue = _Queue("logs", max=10000, silent=True, allow_add_after_close=True) self.logger = logger def worker(please_stop): while not please_stop: _Thread.sleep(1) logs = self.queue.pop_all() for log in logs: if log is _Thread.STOP: if DEBUG_LOGGING: sys.stdout.write( b"TextLog_usingThread.worker() sees stop, filling rest of queue\n" ) please_stop.go() else: self.logger.write(**log) self.thread = _Thread("log thread", worker) self.thread.parent.remove_child( self.thread) # LOGGING WILL BE RESPONSIBLE FOR THREAD stop() self.thread.start()
def __init__(self, logger): if not _Log: _delayed_imports() self.queue = _Queue("logs", max=10000, silent=True) self.logger = logger def worker(please_stop): while not please_stop: Thread.sleep(1) logs = self.queue.pop_all() for log in logs: if log is Thread.STOP: if DEBUG_LOGGING: sys.stdout.write("TextLog_usingThread.worker() sees stop, filling rest of queue\n") please_stop.go() else: self.logger.write(**log) self.thread = Thread("log thread", worker) self.thread.parent.remove_child(self.thread) # LOGGING WILL BE RESPONSIBLE FOR THREAD stop() self.thread.start()