Message356338
Hi.
In order to display the process name in logs, the "logging" module checks for the presence of "multiprocessing" in "sys.modules" before calling "current_process()". If "multiprocessing" is not found in "sys.modules", it assumes that the current process is the main one.
See : https://github.com/python/cpython/blob/af46450bb97ab9bd38748e75aa849c29fdd70028/Lib/logging/__init__.py#L340-L341
However, nothing prevents a child process to delete "sys.module['multiprocessing']", which causes the process name to be wrongly displayed as "MainProcess".
I attached a reproducible example, but this is straightforward to understand. Although it should not happen very often in practice, it is still theoretically possible. Obviously, one could say "just don't clear sys.modules", but I suppose there might exist tools doing such thing for good reasons (like resetting the test environment).
Issues which lead to the current implementation:
- issue4301
- issue7120
- issue8200
Possible fixes:
- Force import "multiprocessing.current_process()" even if not already loaded
- Add function "os.main_pid()" and set "processName" to "MainProcess" only if "os.getpid() == os.main_pid()" |
|
Date |
User |
Action |
Args |
2019-11-10 21:53:15 | Delgan | set | recipients:
+ Delgan |
2019-11-10 21:53:15 | Delgan | set | messageid: <1573422795.72.0.548665383031.issue38762@roundup.psfhosted.org> |
2019-11-10 21:53:15 | Delgan | link | issue38762 messages |
2019-11-10 21:53:15 | Delgan | create | |
|