2015-06-16 97 views
0

當我使用並行python傳遞任何信號量對象或同步對象(如事件,管道,隊列等等)到子進程時遇到問題 當我通過並行python時出現跟隨錯誤一個隊列到子進程。 「通過繼承」%類型(個體經營).__ name__ RuntimeError:隊列對象只能進程之間通過繼承共享在並行進程之間共享信號量對象python

當我用一個多進程庫

import pp 
import time 
from multiprocessing import Event, Queue, Manager, Pool 

e = Queue() 

def startt() : 
    e.put(1) 
    return 1 


ppservers =() 
# Creates jobserver with automatically detected number of workers   
jobServer = pp.Server(ppservers=ppservers,proto=2) 
#submit the work to the job pool or job server 
job = jobServer.submit(startt,(e,),(),("time",), globals = globals()) 
res = job() 
print e.get() 
print res 

回答

0

沒有問題是seeen你」重新當您提交作業有這個問題,因爲你傳遞的隊列對象:

job = jobServer.submit(startt,(e,),(),("time",), globals = globals()) 
#       ^here 

有兩點需要注意:

  1. 隊列已經是全球性的。你不需要將它作爲參數傳遞。

  2. 可以如果您使用過的隊列作爲參數multiprocessing.Manager

manager = multiprocessing.Manager() 
shared_queue = manager.Queue() # this shared queue can be passed as an argument 

manager.Queue()調用實際上將返回一個代理隊列,而不是隊列本身,並且管理器進程將處理後臺中所有必需的同步。

+0

我試着與經理,但我得到認證錯誤,但在我的程序中沒有提供authkey。以下是錯誤信息 – user2088083

+0

answer_challenge中的第435行文件「C:\ Python27 \ lib \ multiprocessing \ connection.py」raise AuthenticationError('摘要發送被拒絕') multiprocessing.AuthenticationError :(AuthenticationError('digest sent was was被拒絕',),<函數RebuildProxy在0x02C81070>,(<函數AutoProxy在0x02C81BF0>,令牌(typeid ='隊列',地址='\\\\。\\ pipe \\ pyc-7364-1-gupzzw', '''''''',''''','''','''','''','''','''','''' task_done')})) – user2088083

+0

@ user2088083回覆在評論中很難理解。作爲一個新問題發佈後續會更好。我還沒有看到那種認證錯誤,所以我認爲我沒有什麼幫助。將它作爲新問題發佈會讓它更具可見性。 – skrrgwasme