In [1]: from multiprocessing import Process
In [2]: import os
In [3]: def run_proc(name):
...: print('Run child process %s (%s)...' % (name, os.getpid()))
...: if __name__=='__main__':
...: print('Parent process %s.' % os.getpid())
...: p = Process(target=run_proc, args=('test',))
...: print('Child process will start.')
...: p.start()
...: p.join()
...: print('Child process end.')
...:
Parent process 4672.
Child process will start.
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "c:\users\administrator\appdata\local\programs\python\python36-32\lib\mul
tiprocessing\spawn.py", line 105, in spawn_main
exitcode = _main(fd)
File "c:\users\administrator\appdata\local\programs\python\python36-32\lib\mul
tiprocessing\spawn.py", line 115, in _main
self = reduction.pickle.load(from_parent)
AttributeError: Can't get attribute 'run_proc' on <module '__main__' (built-in)>
Child process end.
p = Process(target=run_proc, args=('test',))
没有执行并犯了错误
其他人可以正确执行。我不知道为什么