multiprocessing and __main__
Gabriel Genellina
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>
escribió:
> 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
> printed...
>
> 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=())
> p.start()
>
> 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.
--
Gabriel Genellina
More information about the Python-list
mailing list