2015-01-24 5 views
5

Sto tentando di utilizzare una coda multithreading e una coda di multiprocessing allo stesso tempo. La coda di threading verrà utilizzata da 20 thread per recuperare molte pagine Web. Quindi voglio mettere le pagine in una coda multiprocesso in modo che 4 processisti possano eseguire il crunch dei dati. Di seguito è la mia struttura di base. Il mio problema è che, la coda di lavoro, dà un errore dicendo che Coda non è iterabile. Penso che la coda del multithreading stia sovrascrivendo la coda multiprocesso ma non so davvero cosa c'è che non va.Utilizzo di thread e processi insieme alle code condivise in Python

ticker_queue = Queue() 

work_queue = Queue() 
tickers = get_tickers() 


for i in tickers: 
    ticker_queue.put(i) 

for i in range(20): 
    t = Thread(target=network_worker, args = (ticker_queue, work_queue)).start() 

for i in range(4): 
    p = Process(target = worker, args = (work_queue)).start() 

Ecco la traceback

Traceback (most recent call last): 
    File "OneDrive\Python\andys.py", line 108, in <module> 
    p = Process(target = worker, args = (work_queue)).start() 
    File "C:\Python27\lib\multiprocessing\process.py", line 104, in __init__ 
    self._args = tuple(args) 
TypeError: 'Queue' object is not iterable 
+0

bollire il problema in un semplice esempio autonomo, quindi pubblicare l'esempio e il traceback. Nessuno ha visto il professor Xavier per un po '.. ;-) – thebjorn

+0

Devo andare a lavorare in pochi, posterò un esempio autonomo più tardi stasera se nessuno ha risposto. Grazie. – mobone

+0

Manca una virgola: 'p = Processo (target = worker, args = (work_queue,)). Start()' – thebjorn

risposta

8

C'è una virgola mancante nella

p = Process(target = worker, args = (work_queue)).start() 

dal

è solo un'espressione, mentre ciò che si desidera è un Tupla a 1 elemento:

(work_queue,) 

avviso la virgola aggiuntiva.

Problemi correlati