python网络编程 windows下的multiprocessing模块创建进程出现AttributeError: Can't get attribute 'fun' on <module '__main__' (built-in)>错误

 

【ipython错误】

Traceback (most recent call last):
File "<string>", line 1, in <module>
File "d:\software\python\lib\multiprocessing\spawn.py", line 105, in spawn_main
exitcode = _main(fd)
File "d:\software\python\lib\multiprocessing\spawn.py", line 115, in _main
self = reduction.pickle.load(from_parent)
AttributeError: Can't get attribute 'fun' on <module '__main__' (built-in)>
这是父进程
parent a: 1

本地IDE错误
RuntimeError: 
        An attempt has been made to start a new process before the
        current process has finished its bootstrapping phase.

        This probably means that you are not using fork to start your
        child processes and you have forgotten to use the proper idiom
        in the main module:

            if __name__ == '__main__':
                freeze_support()
                ...

        The "freeze_support()" line can be omitted if the program
        is not going to be frozen to produce an executable.

【解决办法】  
  将执行代码放在 if __name__ == "__main__":后,
  详见上篇随笔https://www.cnblogs.com/longyuu/p/14247847.html
posted @ 2021-01-07 18:07  昱成  阅读(4443)  评论(0编辑  收藏  举报