2015-03-03 75 views
0

我將傾錯誤代碼我同時嘗試python腳本窗口:RuntimeError在試圖蟒蛇多處理

預處理驗證數據的前期

使用GPU設備0:特斯拉K20C

Traceback (most recent call last):

File "<string>", line 1, in <module>

File "C:\SciSoft\WinPython-64bit-2.7.6.4\python-2.7.6.amd64\lib\multiprocessing\forking.py", line 380, in main prepare(preparation_data)

File "C:\SciSoft\WinPython-64bit-2.7.6.4\python-2.7.6.amd64\lib\multiprocessing\forking.py", line 495, in prepare '__parents_main__', file, path_name, etc

File "C:\Users\Administrator\Desktop\Galaxy Data\kaggle-galaxies-master\kaggle-galaxies-master\try_convnet_cc_multirotflip_3x69r45_maxout2048_extradense.py", line 133, in <module>

for data, length in create_valid_gen():

File "load_data.py", line 572, in buffered_gen_mp process.start()

'文件「C:\ SciSoft \ WinPython-64-2.7.6.4 \ python的-2.7.6.amd64 \ LIB \ multiprocessing \ process.py「,行130,開頭 self._popen = Popen(self)

文件「C:\ SciSoft \ WinPython-64bit-2.7.6.4 \ python-2.7.6.amd64 \ lib \ multiprocessing \ forking.py」,行258,在init cmd = get_command_line()+ [rhandle]

文件 「C:\ SciSoft \ WinPython-64-2.7.6.4 \蟒-2.7.6.amd64 \ lib中\多\ forking.py」,線358,在get_command_line`

is not going to be frozen to produce a Windows executable.''') 

RuntimeError : 嘗試在當前進程 完成其引導階段之前開始新進程。

 This probably means that you are on Windows and you have 
     forgotten to use the proper idiom in the main module: 

      if __name__ == '__main__': 
       freeze_support() 
       ... 

     The "freeze_support()" line can be omitted if the program 
     is not going to be frozen to produce a Windows executable. 

據我瞭解我要插入一行

if __name__ == '__main__':

一些從哪裏得到它的工作

誰能告訴我其中的文件,我應該插入呢?我已經包含在最初的錯誤日誌

受感染文件被感染的文件列表:

https://github.com/benanne/kaggle-galaxies/blob/master/try_convnet_cc_multirotflip_3x69r45_maxout2048_extradense.py

線131-134

https://github.com/benanne/kaggle-galaxies/blob/master/load_data.py

線572

+0

你能告訴我們你的代碼嗎? – laike9m 2015-03-03 11:33:43

+0

是提供指向文件的鏈接 – 2015-03-03 12:31:27

回答

0

Python documentation在這種情況下非常明顯。
重要部分是Safe importing of main module

您的try_convnet_cc_multirotflip_3x69r45_maxout2048_extradense.py腳本在模塊級別上做了很多事情。如果沒有詳細閱讀它,我已經可以說,你應該換工作流程與功能,並使用它像這樣:

if __name__ == '__main__': 
    freeze_support() # Optional under circumstances described in docs 
    your_workflow_function() 

而且你有問題,這是一個好習慣,不要驚訝您的腳本可能的用戶副作用,如果用戶只是想導入它並重用它的一些功能。
所以不要把你的代碼放在模塊級別。在模塊級別上有常量是可以的,但工作流程應該在函數和類中。
如果要將Python模塊用作腳本(就像您的情況一樣),只需將if __name__ == '__main__'放在該模塊的最後,僅當模塊是解釋器的入口點時才調用your_workflow_function() - 所謂的main module