有以下简单的代码:
from multiprocessing import Process, freeze_support def foo(): print 'hello' if __name__ == '__main__': freeze_support() p = Process(target=foo) p.start()
它适用于Linux或Windows的Python 3.3,但在Python 2.7上失败。
Traceback (most recent call last): File "<string>", line 1, in <module> File "c:\Python27\lib\multiprocessing\forking.py", line 346, in main prepare(preparation_data) File "c:\Python27\lib\multiprocessing\forking.py", line 454, in prepare assert main_name not in sys.modules, main_name AssertionError: thread
一般来说,我试过的所有多处理例子都失败了。 为什么?