Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Multiprocessing spawn processes with the same __name__ #2045

Open
AGPX opened this issue Dec 30, 2019 · 4 comments
Open

Multiprocessing spawn processes with the same __name__ #2045

AGPX opened this issue Dec 30, 2019 · 4 comments
Labels

Comments

@AGPX
Copy link

AGPX commented Dec 30, 2019

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.

@Skylion007
Copy link
Collaborator

We need to set the __name__ variable in the global dict differently in subprocess for py:exec for this to work properly.

@ArthurDeleu
Copy link

Hey, i'm bumping into this same issue, is there any fix yet? Is it possible to manuelly set the __name__upon creation of the CHild Process within the python process called through pybind? @Skylion007 @rwgk

@rwgk
Copy link
Collaborator

rwgk commented Jun 11, 2024

Hey, i'm bumping into this same issue, is there any fix yet? Is it possible to manuelly set the __name__upon creation of the CHild Process within the python process called through pybind? @Skylion007 @rwgk

Could someone please send a PR with a test (that fails)? — That will be the best starting point, to fully define what the problem is, and to try out fixes.

@aaraney
Copy link

aaraney commented Jul 11, 2024

@rwgk, for sure! Just opened #5238.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

5 participants