-
Notifications
You must be signed in to change notification settings - Fork 72
Closed
Description
Problem
The code in the consumer class doesn't guarantee that although the queue has more than two elements, a single consumer can get all the two element. Because other consumers will compete for these elements too, which will often result in a situation that the two elements are got by two different consumers, therefore making the control variable result_size work in an unexpected manner.
Solution
Add a lock when get element from queue.
lock = multiprocessing.Lock()
class ReductionConsumer(multiprocessing.Process):
def __init__(self, task_queue, result_queue):
...
def run(self):
pname = self.name
print("Using process %s..." % pname)
while True:
with lock:
num1 = self.task_queue.get()
...
self.task_queue.task_done()
self.result_queue.put(num1 + num2)Metadata
Metadata
Assignees
Labels
No labels