Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #17699 > unrolled thread
| Started by | Ethan Furman <ethan@stoneleaf.us> |
|---|---|
| First post | 2011-12-21 11:29 -0800 |
| Last post | 2011-12-21 11:29 -0800 |
| 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.
Re: Why does this launch an infinite loop of new processes? Ethan Furman <ethan@stoneleaf.us> - 2011-12-21 11:29 -0800
| From | Ethan Furman <ethan@stoneleaf.us> |
|---|---|
| Date | 2011-12-21 11:29 -0800 |
| Subject | Re: Why does this launch an infinite loop of new processes? |
| Message-ID | <mailman.3957.1324497117.27778.python-list@python.org> |
Andrew Berg wrote:
> I am trying to understand the multiprocessing module, and I tried some
> simple code:
>
> import multiprocessing
> def f():
> print('bla bla')
> p = multiprocessing.Process(target=f)
> p.start()
> p.join()
>
> And the result is a new process that spawns a new process that spawns a
> new process ad infinitum until I log out and the OS forcefully
> terminates all my user processes. I have no idea what is happening; I
> expected it to just print the string and terminate.
>
Anything that runs at import time should be protected by the `if
__name__ == '__main__'` idiom as the children will import the __main__
module.
8<-----------------------------------------------
import multiprocessing
def f():
print('bla bla')
if __name__ == '__main__':
p = multiprocessing.Process(target=f)
p.start()
p.join()
8<-----------------------------------------------
~Ethan~
Back to top | Article view | comp.lang.python
csiph-web