我有这个简单的代码来使事情变得更简单。
from multiprocessing import Process
def abc():
print("HI")
print(a)
a = 4
p = Process(target = abc)
p.start()
Run Code Online (Sandbox Code Playgroud)
它在 ubuntu (Python 3.8.5) 中运行得很好,并提供输出:
HI
4
Run Code Online (Sandbox Code Playgroud)
但是,它在spyder(Python 3.9.5)“AttributeError:无法在<模块' main '(内置)>上获取属性'abc'”和macOS(Python 3.8.10,我也尝试了其他版本)中失败并失败)CLI“运行时错误”。
间谍错误:
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "multiprocessing/spawn.pyc", line 116, in spawn_main
File "multiprocessing/spawn.pyc", line 126, in _main
AttributeError: Can't get attribute 'abc' on <module '__main__' (built-in)>
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "multiprocessing/spawn.pyc", line 116, in spawn_main …Run Code Online (Sandbox Code Playgroud)