Python Glossary Русский

all Python 3multiprocessingfunction

multiprocessing.log_to_stderr()

logging

Turns on output of the multiprocessing internal log to stderr in the format [LEVEL/ProcessName] message and returns that logger.

Syntax

logger = multiprocessing.log_to_stderr(level=None)

Each call adds another handler without checking for an existing one: call it twice and every line is printed twice. Output goes to stderr, not stdout, so a > redirect does not catch it. At logging.INFO you can watch children start and exit; under spawn the level is passed to the children, and they start writing to stderr as well.

Examples

import logging
import multiprocessing as mp
if __name__ == '__main__':
    lg = mp.log_to_stderr(logging.INFO)
    lg.info('hello')  # в stderr: [INFO/MainProcess] hello
    print(len(lg.handlers))  # → 1
    mp.log_to_stderr()
    print(len(lg.handlers))  # → 2 — теперь каждая строка дважды

See also

Open in the full glossarydocs.python.orgReport an inaccuracy