Python multi-process multiprocessing LIFO queue implementation

multiprocessing.queue is close to FIFO and does not come with LIFO implementation. If you want to implement LIFO, here are the methods I can think of so far.

If you have a better way, please advise.

Two ideas:

1. Before entering the mp.queue team, first dequeue the elements previously placed in the team, so that only one element is placed in the team each time (only the latest element is stored in the queue each time, which is partly achieved by LIFO)

2. After leaving the mp.queue team, enter the queue.LifoQueue team. The two queues work together to achieve a LIFO effect.

3. Implemented with basemanager warp: https://stackoverflow.com/questions/33691392/how-to-implement-lifo-for-multiprocessing-queue-in-python

 

LIFO reverse order output can only be performed on the sequence of elements already in the current queue. There is no guarantee that the output will be reversed for all inputs.

Because when the reverse order output occurs, there are subsequent elements that are not input, so it is impossible to reverse the order of those elements.

Published 202 original articles · 80 praised · 300,000 views +

Guess you like

Origin blog.csdn.net/qxqxqzzz/article/details/105101016