Question related to multiprocessing.Process

2013-01-18 Thread Cen Wang
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.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Question related to multiprocessing.Process

2013-01-18 Thread Cen Wang
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  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

-- 
http://mail.python.org/mailman/listinfo/python-list