Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #17728 > unrolled thread

Re: Why does this launch an infinite loop of new processes?

Started byRobert Kern <robert.kern@gmail.com>
First post2011-12-22 11:24 +0000
Last post2011-12-22 11:24 +0000
Articles 1 — 1 participant

Back to article view | Back to comp.lang.python

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

  Re: Why does this launch an infinite loop of new processes? Robert Kern <robert.kern@gmail.com> - 2011-12-22 11:24 +0000

#17728 — Re: Why does this launch an infinite loop of new processes?

FromRobert Kern <robert.kern@gmail.com>
Date2011-12-22 11:24 +0000
SubjectRe: Why does this launch an infinite loop of new processes?
Message-ID<mailman.3974.1324553111.27778.python-list@python.org>
On 12/21/11 8:11 PM, Andrew Berg wrote:
> On 12/21/2011 1:29 PM, Ethan Furman wrote:
>> Anything that runs at import time should be protected by the `if
>> __name__ == '__main__'` idiom as the children will import the __main__
>> module.
> So the child imports the parent and runs the spawn code again? That
> makes sense.

This is a problem with multiprocessing on Windows. Your code would work fine on 
a UNIX system. The problem is that Windows does not have a proper fork() for 
multiprocessing to use. Consequently, it has to start a new Python process from 
scratch and then *import* the main module such that it can properly locate the 
rest of the code to start. If you do not guard the spawning code with a __main__ 
test, then this import will cause an infinite loop.

Just as a further note on these lines, when older versions of setuptools and 
distribute install scripts, they generate stub scripts that do not use a 
__main__ guard, so installing a multiprocessing-using application with 
setuptools can cause this problem. I believe newer versions of distribute has 
this problem fixed, but I'm not sure.

-- 
Robert Kern

"I have come to believe that the whole world is an enigma, a harmless enigma
  that is made terrible by our own mad attempt to interpret it as though it had
  an underlying truth."
   -- Umberto Eco

[toc] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web