Discuss / Python / Anaconda配置的环境下,无法运行本节代码

Anaconda配置的环境下,无法运行本节代码

Topic source

Mahogany3

#1 Created at ... [Delete] [Delete and Lock User]

我和我师兄使用anaconda的windows PC都无法运行上面的代码,比如:

from multiprocessing import Process
import os

# 子进程要执行的代码
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 11272.
Child process will start.
Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "D:\Aapplication\Anaconda\lib\multiprocessing\spawn.py", line 116, in spawn_main
    exitcode = _main(fd, parent_sentinel)
  File "D:\Aapplication\Anaconda\lib\multiprocessing\spawn.py", line 126, in _main
    self = reduction.pickle.load(from_parent)
AttributeError: Can't get attribute 'run_proc' on <module '__main__' (built-in)>
Child process end.

会有上述error


  • 1

Reply