本文整理汇总了Python中logging.handlers.WatchedFileHandler.close方法的典型用法代码示例。如果您正苦于以下问题:Python WatchedFileHandler.close方法的具体用法?Python WatchedFileHandler.close怎么用?Python WatchedFileHandler.close使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类logging.handlers.WatchedFileHandler
的用法示例。
在下文中一共展示了WatchedFileHandler.close方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: close
# 需要导入模块: from logging.handlers import WatchedFileHandler [as 别名]
# 或者: from logging.handlers.WatchedFileHandler import close [as 别名]
def close(self):
self._lock.acquire(timeout=2)
try:
WatchedFileHandler.close(self)
finally:
self._lock.release()
示例2: MPHandler
# 需要导入模块: from logging.handlers import WatchedFileHandler [as 别名]
# 或者: from logging.handlers.WatchedFileHandler import close [as 别名]
class MPHandler(logging.Handler):
"""
Logger class allowing serial logging from multiple processes into a single log file.
To realize this, the MPHandler creates a thread listening for log messages, whereas the
emit method has been overwritten by a method sending the log message to the listening
thread. Therefore, only one process (the one hosting the listener thread) actually writes
into the log file.
"""
def __init__(self, name, mode):
logging.Handler.__init__(self)
self._handler = WatchedFileHandler(name, mode)
self.queue = multiprocessing.Queue(-1)
t = threading.Thread(target=self.receive)
t.daemon = True
t.start()
def setFormatter(self, fmt):
logging.Handler.setFormatter(self, fmt)
self._handler.setFormatter(fmt)
def receive(self):
while True:
try:
record = self.queue.get()
self._handler.emit(record)
except (KeyboardInterrupt, SystemExit):
raise
except EOFError:
break
except:
traceback.print_exc(file=sys.stderr)
def send(self, s):
self.queue.put_nowait(s)
def _format_record(self, record):
# Ensure that exc_info and args have been serialized to strings
# to suppress any chance of them not being able to be pickled.
# Furthermore, this possibly reduces the size of messages sent
# over the pipe.
if record.args:
record.msg = record.msg % record.args
record.args = None
if record.exc_info:
self.format(record)
record.exc_info = None
return record
def emit(self, record):
try:
s = self._format_record(record)
self.send(s)
except (KeyboardInterrupt, SystemExit):
raise
except:
self.handleError(record)
def close(self):
self._handler.close()
logging.Handler.close(self)