import time
import multiprocessing
def multi_thread(files):
q = multiprocessing.Queue()
for f in files:
q.put(f)
p = multiprocessing.Pool(5)
for i in range(5):
p.apply_async(worker_test, args=(q,))
p.close()
p.join()
def worker_test(i):
print 'hello'
print i
def main():
files = ['a', 'b', 'c', 'd']
multi_thread(files[0:4])
print 'Multi-thread time: {0} seconds'.format(time.time() - t0)
if __name__ == '__main__':
main()
My code doesn't even enter the work_test()
function to print hello
if I pass in q
. But if I change q
to i
, the code runs fine. Somehow it doesn't like the multiprocessing.Queue()
object - any ideas what's going on?