why doesn't a simple python producer/consumer multi-threading program speed up by adding the number of workers?
问题 The code below is almost identical to the python official Queue example at http://docs.python.org/2/library/queue.html from Queue import Queue from threading import Thread from time import time import sys num_worker_threads = int(sys.argv[1]) source = xrange(10000) def do_work(item): for i in xrange(100000): pass def worker(): while True: item = q.get() do_work(item) q.task_done() q = Queue() for item in source: q.put(item) start = time() for i in range(num_worker_threads): t = Thread(target