

@contextlib.contextmanager
def logging_context(logging_configurer_fn, logging_level=logging.DEBUG):
    'A context manager that creates a separate process for logging.\n\n    Sets up the current process to log via a multiprocessing queue to the\n    logging process.\n\n    Note that after the scope of the context, logging will cease to function as\n    it will be queuing log entries for the expired logging process.\n\n    :logging_configurer_fn: a callable to configure logging process\n    :logging_level: optional logging level, defaults to logging.DEBUG\n\n    '
    logging_queue = multiprocessing.Queue()
    logging_process_object = multiprocessing.Process(target=_logging_process, args=(logging_queue, logging_configurer_fn))
    logging_process_object.start()
    handler = _QueueLoggingHandler(logging_queue)
    root_logger = logging.getLogger()
    root_logger.addHandler(handler)
    root_logger.setLevel(logging_level)
    try:
        (yield)
    finally:
        root_logger.removeHandler(handler)
        logging_queue.put_nowait(None)
        logging_process_object.join()

dataset/ETHPy150Open bloomberg/phabricator-tools/py/phl/phlsys_multiprocessing.py logging_context/original