Question related to multiprocessing.Process

C

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.
 
C

Chris Angelico

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
 
C

Cen Wang

Thanks! It now works!
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
 
C

Cen Wang

Thanks! It now works!
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
 
T

Terry Reedy

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,057
Latest member
KetoBeezACVGummies

Latest Threads

Top