一.linux
1.可能没有此模块,会抛出异常cannot import name Process,需要安装一下,在终端中使用pip install multiprocessing安装即可。
2.注意不要将文件明设置为multiprocessing.py
二.windows
1.注意不要将文件明设置为multiprocessing.py
2.可能会需要在终端中运行,不一定。在IDE中运行错误,可以尝试在终端中试试。
3.抛出RuntimeError, 解决办法:
需要在p = Process()前加上
if __name__ == "__main__":
之后的代码,包括主进程的代码都在这里边写。如下所示:
if __name__ == "__main__": p = Process(target=ob) p.start() p.join(2) while True: print("---main---") time.sleep(1)