當前位置: 首頁>>代碼示例>>Python>>正文


Python logging._releaseLock方法代碼示例

本文整理匯總了Python中logging._releaseLock方法的典型用法代碼示例。如果您正苦於以下問題:Python logging._releaseLock方法的具體用法?Python logging._releaseLock怎麽用?Python logging._releaseLock使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在logging的用法示例。


在下文中一共展示了logging._releaseLock方法的13個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: SetLogPrefix

# 需要導入模塊: import logging [as 別名]
# 或者: from logging import _releaseLock [as 別名]
def SetLogPrefix(prefix):
  """Adds a prefix to the log handler to identify the process.

  Args:
    prefix: The prefix string to append at the beginning of each line.
  """
  formatter = logging.Formatter(
      str(prefix) + ' [%(filename)s:%(lineno)d] %(levelname)s %(message)s')
  logging._acquireLock()
  try:
    for handler in logging._handlerList:
      if isinstance(handler, weakref.ref):
        handler = handler()
      if handler:
        handler.setFormatter(formatter)
  finally:
    logging._releaseLock() 
開發者ID:elsigh,項目名稱:browserscope,代碼行數:19,代碼來源:dev_appserver_multiprocess.py

示例2: tearDown

# 需要導入模塊: import logging [as 別名]
# 或者: from logging import _releaseLock [as 別名]
def tearDown(self):
        """Remove our logging stream, and restore the original logging
        level."""
        self.stream.close()
        self.root_logger.removeHandler(self.root_hdlr)
        while self.root_logger.handlers:
            h = self.root_logger.handlers[0]
            self.root_logger.removeHandler(h)
            h.close()
        self.root_logger.setLevel(self.original_logging_level)
        logging._acquireLock()
        try:
            logging._levelNames.clear()
            logging._levelNames.update(self.saved_level_names)
            logging._handlers.clear()
            logging._handlers.update(self.saved_handlers)
            logging._handlerList[:] = self.saved_handler_list
            loggerDict = logging.getLogger().manager.loggerDict
            loggerDict.clear()
            loggerDict.update(self.saved_loggers)
        finally:
            logging._releaseLock() 
開發者ID:IronLanguages,項目名稱:ironpython2,代碼行數:24,代碼來源:test_logging.py

示例3: revision_add_handler

# 需要導入模塊: import logging [as 別名]
# 或者: from logging import _releaseLock [as 別名]
def revision_add_handler(self, hdlr):  # 從添加源頭阻止同一個logger添加同類型的handler。
    """
    Add the specified handler to this logger.
    """
    logging._acquireLock()

    try:
        """ 官方的
        if not (hdlr in self.handlers):
            self.handlers.append(hdlr)
        """
        hdlrx_type_set = set()
        for hdlrx in self.handlers:
            hdlrx_type = type(hdlrx)
            if hdlrx_type == logging.StreamHandler:  # REMIND 因為很多handler都是繼承自StreamHandler,包括filehandler,直接判斷會邏輯出錯。
                hdlrx_type = ColorHandler
            hdlrx_type_set.add(hdlrx_type)

        hdlr_type = type(hdlr)
        if hdlr_type == logging.StreamHandler:
            hdlr_type = ColorHandler
        if hdlr_type not in hdlrx_type_set:
            self.handlers.append(hdlr)
    finally:
        logging._releaseLock() 
開發者ID:ydf0509,項目名稱:distributed_framework,代碼行數:27,代碼來源:log_manager000.py

示例4: fileConfig

# 需要導入模塊: import logging [as 別名]
# 或者: from logging import _releaseLock [as 別名]
def fileConfig(fname, defaults=None, disable_existing_loggers=True):
    """
    Read the logging configuration from a ConfigParser-format file.

    This can be called several times from an application, allowing an end user
    the ability to select from various pre-canned configurations (if the
    developer provides a mechanism to present the choices and load the chosen
    configuration).
    """
    import configparser

    cp = configparser.ConfigParser(defaults)
    if hasattr(fname, 'readline'):
        cp.read_file(fname)
    else:
        cp.read(fname)

    formatters = _create_formatters(cp)

    # critical section
    logging._acquireLock()
    try:
        logging._handlers.clear()
        del logging._handlerList[:]
        # Handlers add themselves to logging._handlers
        handlers = _install_handlers(cp, formatters)
        _install_loggers(cp, handlers, disable_existing_loggers)
    finally:
        logging._releaseLock() 
開發者ID:war-and-code,項目名稱:jawfish,代碼行數:31,代碼來源:config.py

示例5: stopListening

# 需要導入模塊: import logging [as 別名]
# 或者: from logging import _releaseLock [as 別名]
def stopListening():
    """
    Stop the listening server which was created with a call to listen().
    """
    global _listener
    logging._acquireLock()
    try:
        if _listener:
            _listener.abort = 1
            _listener = None
    finally:
        logging._releaseLock() 
開發者ID:war-and-code,項目名稱:jawfish,代碼行數:14,代碼來源:config.py

示例6: get_logger

# 需要導入模塊: import logging [as 別名]
# 或者: from logging import _releaseLock [as 別名]
def get_logger():
    '''
    Returns logger used by multiprocessing
    '''
    global _logger
    import logging

    logging._acquireLock()
    try:
        if not _logger:

            _logger = logging.getLogger(LOGGER_NAME)
            _logger.propagate = 0
            logging.addLevelName(SUBDEBUG, 'SUBDEBUG')
            logging.addLevelName(SUBWARNING, 'SUBWARNING')

            # XXX multiprocessing should cleanup before logging
            if hasattr(atexit, 'unregister'):
                atexit.unregister(_exit_function)
                atexit.register(_exit_function)
            else:
                atexit._exithandlers.remove((_exit_function, (), {}))
                atexit._exithandlers.append((_exit_function, (), {}))

    finally:
        logging._releaseLock()

    return _logger 
開發者ID:war-and-code,項目名稱:jawfish,代碼行數:30,代碼來源:util.py

示例7: resetLoggingLocks

# 需要導入模塊: import logging [as 別名]
# 或者: from logging import _releaseLock [as 別名]
def resetLoggingLocks():
	'''
	This function is a HACK!

	Basically, if we fork() while a logging lock is held, the lock
	is /copied/ while in the acquired state. However, since we've
	forked, the thread that acquired the lock no longer exists,
	so it can never unlock the lock, and we end up blocking
	forever.

	Therefore, we manually enter the logging module, and forcefully
	release all the locks it holds.

	THIS IS NOT SAFE (or thread-safe).
	Basically, it MUST be called right after a process
	starts, and no where else.
	'''
	try:
		logging._releaseLock()
	except RuntimeError:
		pass  # The lock is already released

	# Iterate over the root logger hierarchy, and
	# force-free all locks.
	# if logging.Logger.root
	for handler in logging.Logger.manager.loggerDict.values():
		if hasattr(handler, "lock") and handler.lock:
			try:
				handler.lock.release()
			except RuntimeError:
				pass  # The lock is already released 
開發者ID:fake-name,項目名稱:ReadableWebProxy,代碼行數:33,代碼來源:logSetup.py

示例8: fileConfig

# 需要導入模塊: import logging [as 別名]
# 或者: from logging import _releaseLock [as 別名]
def fileConfig(fname, defaults=None, disable_existing_loggers=True):
    """
    Read the logging configuration from a ConfigParser-format file.

    This can be called several times from an application, allowing an end user
    the ability to select from various pre-canned configurations (if the
    developer provides a mechanism to present the choices and load the chosen
    configuration).
    """
    import ConfigParser

    cp = ConfigParser.ConfigParser(defaults)
    if hasattr(fname, 'readline'):
        cp.readfp(fname)
    else:
        cp.read(fname)

    formatters = _create_formatters(cp)

    # critical section
    logging._acquireLock()
    try:
        logging._handlers.clear()
        del logging._handlerList[:]
        # Handlers add themselves to logging._handlers
        handlers = _install_handlers(cp, formatters)
        _install_loggers(cp, handlers, disable_existing_loggers)
    finally:
        logging._releaseLock() 
開發者ID:glmcdona,項目名稱:meddle,代碼行數:31,代碼來源:config.py

示例9: __init__

# 需要導入模塊: import logging [as 別名]
# 或者: from logging import _releaseLock [as 別名]
def __init__(self, host='localhost', port=DEFAULT_LOGGING_CONFIG_PORT,
                     handler=None, ready=None):
            ThreadingTCPServer.__init__(self, (host, port), handler)
            logging._acquireLock()
            self.abort = 0
            logging._releaseLock()
            self.timeout = 1
            self.ready = ready 
開發者ID:glmcdona,項目名稱:meddle,代碼行數:10,代碼來源:config.py

示例10: serve_until_stopped

# 需要導入模塊: import logging [as 別名]
# 或者: from logging import _releaseLock [as 別名]
def serve_until_stopped(self):
            import select
            abort = 0
            while not abort:
                rd, wr, ex = select.select([self.socket.fileno()],
                                           [], [],
                                           self.timeout)
                if rd:
                    self.handle_request()
                logging._acquireLock()
                abort = self.abort
                logging._releaseLock()
            self.socket.close() 
開發者ID:glmcdona,項目名稱:meddle,代碼行數:15,代碼來源:config.py

示例11: run

# 需要導入模塊: import logging [as 別名]
# 或者: from logging import _releaseLock [as 別名]
def run(self):
            server = self.rcvr(port=self.port, handler=self.hdlr,
                               ready=self.ready)
            if self.port == 0:
                self.port = server.server_address[1]
            self.ready.set()
            global _listener
            logging._acquireLock()
            _listener = server
            logging._releaseLock()
            server.serve_until_stopped() 
開發者ID:glmcdona,項目名稱:meddle,代碼行數:13,代碼來源:config.py

示例12: setUp

# 需要導入模塊: import logging [as 別名]
# 或者: from logging import _releaseLock [as 別名]
def setUp(self):
        """Setup the default logging stream to an internal StringIO instance,
        so that we can examine log output as we want."""
        logger_dict = logging.getLogger().manager.loggerDict
        logging._acquireLock()
        try:
            self.saved_handlers = logging._handlers.copy()
            self.saved_handler_list = logging._handlerList[:]
            self.saved_loggers = logger_dict.copy()
            self.saved_level_names = logging._levelNames.copy()
        finally:
            logging._releaseLock()

        # Set two unused loggers: one non-ASCII and one Unicode.
        # This is to test correct operation when sorting existing
        # loggers in the configuration code. See issue 8201.
        logging.getLogger("\xab\xd7\xbb")
        logging.getLogger(u"\u013f\u00d6\u0047")

        self.root_logger = logging.getLogger("")
        self.original_logging_level = self.root_logger.getEffectiveLevel()

        self.stream = cStringIO.StringIO()
        self.root_logger.setLevel(logging.DEBUG)
        self.root_hdlr = logging.StreamHandler(self.stream)
        self.root_formatter = logging.Formatter(self.log_format)
        self.root_hdlr.setFormatter(self.root_formatter)
        self.root_logger.addHandler(self.root_hdlr) 
開發者ID:IronLanguages,項目名稱:ironpython2,代碼行數:30,代碼來源:test_logging.py

示例13: get_logger

# 需要導入模塊: import logging [as 別名]
# 或者: from logging import _releaseLock [as 別名]
def get_logger():
    '''
    Returns logger used by multiprocessing
    '''
    global _logger
    import logging, atexit

    logging._acquireLock()
    try:
        if not _logger:

            _logger = logging.getLogger(LOGGER_NAME)
            _logger.propagate = 0
            logging.addLevelName(SUBDEBUG, 'SUBDEBUG')
            logging.addLevelName(SUBWARNING, 'SUBWARNING')

            # XXX multiprocessing should cleanup before logging
            if hasattr(atexit, 'unregister'):
                atexit.unregister(_exit_function)
                atexit.register(_exit_function)
            else:
                atexit._exithandlers.remove((_exit_function, (), {}))
                atexit._exithandlers.append((_exit_function, (), {}))

    finally:
        logging._releaseLock()

    return _logger 
開發者ID:IronLanguages,項目名稱:ironpython2,代碼行數:30,代碼來源:util.py


注:本文中的logging._releaseLock方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。