当前位置: 首页>>代码示例>>Python>>正文


Python WatchedFileHandler.close方法代码示例

本文整理汇总了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()
开发者ID:jay-katta,项目名称:wok,代码行数:9,代码来源:safewatchedfilehandler.py

示例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)
开发者ID:daemotron,项目名称:backtory,代码行数:66,代码来源:log.py


注:本文中的logging.handlers.WatchedFileHandler.close方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。