本文整理汇总了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()
示例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()
示例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()
示例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()
示例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()
示例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
示例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
示例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()
示例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
示例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()
示例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()
示例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)
示例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