multiprocessing and __main__
gagsl-py2 at yahoo.com.ar
Sun Jul 26 04:14:34 EDT 2009
En Sun, 26 Jul 2009 02:52:36 -0300, is un <israel.unterman at gmail.com>
> Trying the multiprocessing module for the first time, I spent quite a
> bit on making this code run:
> The result was not what I expected, it seems like the process restarts
> all the time, and the message 'Process started' keeps getting
> Going back to the documentation, I realized that the doc was really
> serious about the line:
> if __name__ == '__main__' .. which I always ignore, and by changing
> the code to
> if __name__ == '__main__':
> p = Process(target=my_process, args=())
> print 'Process started'
> the problem was solved.
> So my question is what actually happens when I call p.start()? Is the
> entry file reloaded under a different module name?
The multiprocessing module handles multiple (separate) processes. On
Windows, a new Python interpreter is launched; on other OSs a different
approach is used. In any case, you get distinct and separate processes,
each one with its own set of loaded modules, etc.
More information about the Python-list