Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python 2.7 on Windows, "assert main_name not in sys.modules, main_name" for all multiprocessing examples

There is following simple code:

from multiprocessing import Process, freeze_support

def foo():
    print 'hello'

if __name__ == '__main__':
    freeze_support()
    p = Process(target=foo)
    p.start()

It works good on Linux or Windows with Python 3.3, but fails on Windows with 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

Generally speaking, all multiprocessing examples i tried fail on that setup. Why?

like image 546
clumpter Avatar asked May 06 '13 19:05

clumpter


1 Answers

This is a known bug:

http://bugs.python.org/issue10845

Not sure if this will ever get ported to 2.7.X.

like image 170
Nick Avatar answered Sep 28 '22 19:09

Nick