Utilisez parallel
test.py
#!/usr/bin/python
import parallel
from Queue import Queue as Q1
from multiprocessing import Queue as Q2
q1 = Q1()
q2 = Q2()
for i in xrange(6):
q1.put(i)
q2.put(i)
def worker(q1, q2):
print '%6d %6d' % (q1.get(), q2.get())
#--- THREADING
print '\n--- thread ---'
print ' Queue1 Queue2'
print '--------------'
parallel.thread(worker, [q1, q2], 3)
#--- MULTIPROCESS
print '\n--- multiprocess ---'
print ' Queue1 Queue2'
print '--------------------'
parallel.multiprocess(worker, [q1, q2], 3)
résultat
--- thread ---
Queue1 Queue2
--------------
0 0
1 1
2 2
--- multiprocess ---
Queue1 Queue2
--------------------
3 3
3 4
3 5
Conclusion
Utiliser la file d'attente multitraitement
Recommended Posts