0
from multiprocessing import Process
import os
import time

def info(title):
    print(title)
    print('module name:',__name__)
    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()

'''The result is under below:''' Obviously, the multiprocessing cannot work as expected,why?

main line
module name: __main__
process id: 10548
Weiziyoung
  • 191
  • 1
  • 2
  • 12
  • 1
    **Do not use IDLE to run that code**. Try to run it from an actual terminal... The issue is that the subprocess is outputting on the real `stdout` of the process, which is *not* the IDLE console. – Bakuriu Nov 01 '16 at 07:45
  • This code works for me. It has something to do with your environment. – Jordan McQueen Nov 01 '16 at 07:45
  • Thanks!When I run it in 'cmd',It prints results successfully! – Weiziyoung Nov 01 '16 at 08:17

0 Answers0