Reputation: 35213
I am trying out the examples listed in the python docs http://docs.python.org/library/multiprocessing.html particularly these two on Windows:
1)
from multiprocessing import Process
def f(name):
print 'hello', name
if __name__ == '__main__':
p = Process(target=f, args=('bob',))
p.start()
p.join()
2)
from multiprocessing import Process
import os
def info(title):
print title
print 'module name:', __name__
print 'parent process:', os.getppid()
print 'process id:', os.getpid()
def f(name):
info('function f')
print 'hello', name
if __name__ == '__main__':
info('main line')
p = Process(target=f, args=('bob',))
p.start()
p.join()
Here is the problem: I don't get any output from the child process. It works on Linux though. What is going on?
Upvotes: 4
Views: 8321
Reputation: 1200
example 1 works well.( I hope you saved the program in a file and then executed it else it will not recognise the function f at all).
example 2 won't work if u want the parent process's id. There is no getppid in windows.
Just take the print os.getppid and execute, its brilliant as ever !
Please refer this for more by Doug. (UPDATE: The original link isn't working, here is something similar.)
Upvotes: 2