2013-05-06 15 views
7

C'è seguente codice semplice:Python 2.7 su Windows, "affermare main_name non in sys.modules, main_name" per tutti gli esempi Multiprocessing

from multiprocessing import Process, freeze_support 

def foo(): 
    print 'hello' 

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

Funziona bene su Linux o Windows con Python 3.3, ma non riesce a Windows con 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 

In generale, tutti gli esempi di multiprocessing hanno provato un errore in quella configurazione. Perché?

risposta

10

Questo è un bug noto:

http://bugs.python.org/issue10845

Non so se questo potrà mai arrivare al porting 2.7.X.

+2

Questo problema verrà risolto in 2.7.11 - https://hg.python.org/cpython/rev/5d88c1d413b9/ –

+0

@techtonik Grazie per l'indizio. Significa che il modulo 'multiprocessing' non è disponibile nelle versioni <= 2.7.10? – Zelong

+0

@Zelong è disponibile, potrebbe non funzionare correttamente in questi casi. –

Problemi correlati