为什么python2.7中用Process创建子进程的语句之前必须加#if _name__ == '__main__'?
from multiprocessing import Process
import os
def run(name):
print 'The child process \'%s\' (pid %d) is running' % (name, os.getpid())
return
print 'The parent process(pid %d) is running' % os.getpid()
p = Process(target=run, args = ('test', ))
print 'The child process is ready to run!'
p.start();
p.join();
print 'The child process ends!'
这段程序运行就会提示错误
"Attempt to start a new process before the current process
has finished its bootstrapping phase."
就不给你看
9 years, 5 months ago