简体   繁体   中英

How to configure thread names for multiprocessing.BaseManager instances

There's some usage of these BaseManager types in some code I'm debugging. https://docs.python.org/3/library/multiprocessing.html#multiprocessing.managers.BaseManager

from multiprocessing.managers import BaseManager

The log configuration for our process has the thread name expressed using the standard record attribute %(threadName)s .

This results in the typical indexed format you find in multithreaded log traces from threads that do not get names ascribed to them

BaseManager-15|MainProcess
BaseManager-17|MainProcess
BaseManager-38|MainProcess

Is there a way to get threads under a BaseManager to have their thread name specified?

Looking at the implementation for the managers.py source there may be something possible under the member _process , possibly through the _ctx entity

        # spawn process which runs a server
        self._process = self._ctx.Process(
            target=type(self)._run_server,
            args=(self._registry, self._address, self._authkey,
                  self._serializer, writer, initializer, initargs),
            )
        ident = ':'.join(str(i) for i in self._process._identity)
        self._process.name = type(self).__name__  + '-' + ident
        self._process.start()

https://github.com/python/cpython/blob/27e59afa2ad98e6bfe26c6b2b7f6294fa561680c/Lib/multiprocessing/managers.py#L561

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM