pybind11 icon indicating copy to clipboard operation
pybind11 copied to clipboard

Multiprocessing spawn processes with the same __name__

Open AGPX opened this issue 5 years ago • 6 comments

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.

AGPX avatar Dec 30 '19 16:12 AGPX