Skip to content

Process name not propagated to logging library #143

@noxdafox

Description

@noxdafox

Greetings,

When investigating the following bug:
noxdafox/pebble#113

It turned out the multiprocess library seems to not propagate the process name to the logging library correctly.

import logging
import multiprocess
import multiprocessing


logging.basicConfig(format='%(processName)s-%(process)d - %(levelname)s:%(message)s', level=logging.DEBUG)


def standardlib():
    logger.error("Using multiprocessing")
    logger.error(multiprocessing.current_process().name)


def externallib():
    logger.error("Using multiprocess")
    logger.error(multiprocess.current_process().name)


if __name__ == "__main__":
    logger = logging.getLogger("main")

    p = multiprocessing.Process(target=standardlib, name="multiprocessing")
    p.start()
    p.join()

    p = multiprocess.Process(target=externallib, name="multiprocess")
    p.start()
    p.join()

Output:

multiprocessing-7814 - ERROR:Using multiprocessing
multiprocessing-7814 - ERROR:multiprocessing
MainProcess-7815 - ERROR:Using multiprocess
MainProcess-7815 - ERROR:multiprocess

The expected output would be:

multiprocessing-7814 - ERROR:Using multiprocessing
multiprocessing-7814 - ERROR:multiprocessing
multiprocess-7815 - ERROR:Using multiprocess
multiprocess-7815 - ERROR:multiprocess
$ python --version
Python 3.9.2

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions