Multiprocessing spawn processes with the same __name__
Nobody has claimed this yet.
- Dominant language
- C++
- Stars
- 18k
- Forks
- 2.3k
- Avg merge
- 5d 17h
- Merged PRs (30d)
- 10
Description
I have a code that use the multiprocessing module to spawn new processes like this:
...
ctx = multiprocessing.get_context('spawn')
process = ctx.Process(target=_worker, args=args, daemon=True)
process.start()
...
I have to distinguish them from the main execution, through the code:
if __name__ == '__main__':
...
If I run this script from command line (running Python.exe), the __name__ is different for each process. When I run it through the py::exec, the __name__ is always __main__. How can I overcome this issue? Thanks.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the multiprocessing spawn example and the py::exec execution path described in the issue, then compare how each process receives its name. No files or tests are named; done means identifying whether py::exec can provide distinct execution context and documenting a verified way to distinguish the spawned processes from the main execution.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- cpp, python
- Domain
- backend
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 30/100