Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #37048 > unrolled thread
| Started by | Cen Wang <iwarobots@gmail.com> |
|---|---|
| First post | 2013-01-18 20:50 -0800 |
| Last post | 2013-01-19 06:27 -0500 |
| Articles | 5 — 3 participants |
Back to article view | Back to comp.lang.python
Question related to multiprocessing.Process Cen Wang <iwarobots@gmail.com> - 2013-01-18 20:50 -0800
Re: Question related to multiprocessing.Process Chris Angelico <rosuav@gmail.com> - 2013-01-19 16:05 +1100
Re: Question related to multiprocessing.Process Cen Wang <iwarobots@gmail.com> - 2013-01-18 21:33 -0800
Re: Question related to multiprocessing.Process Cen Wang <iwarobots@gmail.com> - 2013-01-18 21:33 -0800
Re: Question related to multiprocessing.Process Terry Reedy <tjreedy@udel.edu> - 2013-01-19 06:27 -0500
| From | Cen Wang <iwarobots@gmail.com> |
|---|---|
| Date | 2013-01-18 20:50 -0800 |
| Subject | Question related to multiprocessing.Process |
| Message-ID | <6816f48f-753f-4ae3-be79-3b16bd83e6f2@googlegroups.com> |
Hi, when I use multiprocessing.Process in this way:
from multiprocessing import Process
class MyProcess(Process):
def __init__(self):
Process.__init__(self)
def run(self):
print 'x'
p = MyProcess()
p.start()
It just keeps printing 'x' on my command prompt and does not end. But I think MyProcess should print an 'x' and then terminate. I don't why this is happening. I'm using Win7 64 bit, Python 2.7.3. Any idea? Thanks in advance.
[toc] | [next] | [standalone]
| From | Chris Angelico <rosuav@gmail.com> |
|---|---|
| Date | 2013-01-19 16:05 +1100 |
| Message-ID | <mailman.665.1358571909.2939.python-list@python.org> |
| In reply to | #37048 |
On Sat, Jan 19, 2013 at 3:50 PM, Cen Wang <iwarobots@gmail.com> wrote:
> Hi, when I use multiprocessing.Process in this way:
>
> from multiprocessing import Process
>
> class MyProcess(Process):
>
> def __init__(self):
> Process.__init__(self)
>
> def run(self):
> print 'x'
>
> p = MyProcess()
> p.start()
>
> It just keeps printing 'x' on my command prompt and does not end. But I think MyProcess should print an 'x' and then terminate. I don't why this is happening. I'm using Win7 64 bit, Python 2.7.3. Any idea? Thanks in advance.
Multiprocessing on Windows requires that your module be importable. So
it imports your main module, which instantiates another MyProcess,
starts it, rinse and repeat. You'll need to protect your main routine
code:
if __name__=="__main__":
p = MyProcess()
p.start()
ChrisA
[toc] | [prev] | [next] | [standalone]
| From | Cen Wang <iwarobots@gmail.com> |
|---|---|
| Date | 2013-01-18 21:33 -0800 |
| Message-ID | <044321bf-8e91-4a63-9a78-99a3ec5e40db@googlegroups.com> |
| In reply to | #37050 |
Thanks! It now works! On Saturday, 19 January 2013 13:05:07 UTC+8, Chris Angelico wrote: > On Sat, Jan 19, 2013 at 3:50 PM, Cen Wang <iwarobots@gmail.com> wrote: > > > Hi, when I use multiprocessing.Process in this way: > > > > > > from multiprocessing import Process > > > > > > class MyProcess(Process): > > > > > > def __init__(self): > > > Process.__init__(self) > > > > > > def run(self): > > > print 'x' > > > > > > p = MyProcess() > > > p.start() > > > > > > It just keeps printing 'x' on my command prompt and does not end. But I think MyProcess should print an 'x' and then terminate. I don't why this is happening. I'm using Win7 64 bit, Python 2.7.3. Any idea? Thanks in advance. > > > > Multiprocessing on Windows requires that your module be importable. So > > it imports your main module, which instantiates another MyProcess, > > starts it, rinse and repeat. You'll need to protect your main routine > > code: > > > > if __name__=="__main__": > > p = MyProcess() > > p.start() > > > > ChrisA
[toc] | [prev] | [next] | [standalone]
| From | Cen Wang <iwarobots@gmail.com> |
|---|---|
| Date | 2013-01-18 21:33 -0800 |
| Message-ID | <mailman.668.1358573617.2939.python-list@python.org> |
| In reply to | #37050 |
Thanks! It now works! On Saturday, 19 January 2013 13:05:07 UTC+8, Chris Angelico wrote: > On Sat, Jan 19, 2013 at 3:50 PM, Cen Wang <iwarobots@gmail.com> wrote: > > > Hi, when I use multiprocessing.Process in this way: > > > > > > from multiprocessing import Process > > > > > > class MyProcess(Process): > > > > > > def __init__(self): > > > Process.__init__(self) > > > > > > def run(self): > > > print 'x' > > > > > > p = MyProcess() > > > p.start() > > > > > > It just keeps printing 'x' on my command prompt and does not end. But I think MyProcess should print an 'x' and then terminate. I don't why this is happening. I'm using Win7 64 bit, Python 2.7.3. Any idea? Thanks in advance. > > > > Multiprocessing on Windows requires that your module be importable. So > > it imports your main module, which instantiates another MyProcess, > > starts it, rinse and repeat. You'll need to protect your main routine > > code: > > > > if __name__=="__main__": > > p = MyProcess() > > p.start() > > > > ChrisA
[toc] | [prev] | [next] | [standalone]
| From | Terry Reedy <tjreedy@udel.edu> |
|---|---|
| Date | 2013-01-19 06:27 -0500 |
| Message-ID | <mailman.687.1358594886.2939.python-list@python.org> |
| In reply to | #37048 |
On 1/19/2013 12:05 AM, Chris Angelico wrote: > On Sat, Jan 19, 2013 at 3:50 PM, Cen Wang <iwarobots@gmail.com> wrote: >> Hi, when I use multiprocessing.Process in this way: >> >> from multiprocessing import Process >> >> class MyProcess(Process): >> >> def __init__(self): >> Process.__init__(self) >> >> def run(self): >> print 'x' >> >> p = MyProcess() >> p.start() >> >> It just keeps printing 'x' on my command prompt and does not end. But I think MyProcess should print an 'x' and then terminate. I don't why this is happening. I'm using Win7 64 bit, Python 2.7.3. Any idea? Thanks in advance. > > Multiprocessing on Windows requires that your module be importable. So > it imports your main module, which instantiates another MyProcess, > starts it, rinse and repeat. You'll need to protect your main routine > code: > > if __name__=="__main__": > p = MyProcess() > p.start() This is documented in 17.2.3. Programming guidelines 17.2.3.2. Windows -- Terry Jan Reedy
[toc] | [prev] | [standalone]
Back to top | Article view | comp.lang.python
csiph-web