Title: There is no proper way to know if a process is the main one
Type: enhancement Stage: patch review
Components: Library (Lib) Versions:
Status: open Resolution:
Dependencies: Superseder:
Assigned To: Nosy List: Delgan, ZackerySpytz, davin, pablogsal, pitrou
Priority: normal Keywords: patch

Created on 2019-10-18 20:48 by Delgan, last changed 2020-12-02 23:59 by ZackerySpytz.

Pull Requests
URL Status Linked Edit
PR 23621 open ZackerySpytz, 2020-12-02 23:59
Messages (1)
msg354918 - (view) Author: Delgan (Delgan) * Date: 2019-10-18 20:48

I noticed that there exists the function "threading.main_thread()", but there is no equivalent for the "multiprocessing" module.

Is there a reason for this absence?

These StackOverflow questions are related to this problem:

Current proposed solutions have flaws.
It's suggested to check if "current_process().name == 'MainProcess'" but anyone can re-write the name of a process with "current_process().name = 'foobar'" so this does not seem to be a reliable solution.
Another alternative is to check for the type of the process, which is different for main and child, respectively "mulitprocessing.process._MainProcess" and "multiprocessing.process.Process". This is obviously hacky as it relies on implementation detail.

What are you thoughts on adding a new "multiprocessing.main_process()" function?
Date User Action Args
2020-12-02 23:59:25ZackerySpytzsetkeywords: + patch
nosy: + ZackerySpytz

pull_requests: + pull_request22489
stage: patch review
2019-10-19 20:14:43pablogsalsetnosy: + pablogsal
2019-10-18 23:09:05ned.deilysetnosy: + pitrou, davin
2019-10-18 20:48:15Delgancreate