I am using multiprocessing to process my records.
queue = Queue()
def produce(i, item):
data = process(i, item)
queue.put(data)
def process(i, item):
data = do_processing(i, item)
return data
if __name__ == '__main__':
records = load_records()
with ProcessPoolExecutor(max_workers=os.cpu_count()) as executor:
print('produce items')
for i, item in ennumerate(records.items()):
executor.submit(produce, i, item)
print('queue size:{}'.format(queue.qsize()))
while not queue.empty():
save(queue.get())
Here I put records in a queue from produce as that step is time-consuming. After processing the records, I save them. As the consume step is not time consuming, I don't bother to run it in a separate thread.
Here after I execute the code, the queue remains empty. What is going on here?