Clean way to get near-LIFO behavior from multiprocessing.Queue? (or even just *not* near-FIFO)

后端 未结 2 792
Happy的楠姐
Happy的楠姐 2021-01-12 07:39

Does anyone know a clean way to get near-LIFO or even not near-FIFO (e.g. random) behavior from multiprocessing.Queue?

Alternative Question: Cou

2条回答
  •  鱼传尺愫
    2021-01-12 08:24

    There is a LIFO queue in the Queue package (queue in Python 3). This isn't exposed in the multiprocessing or multiprocessing.queues modules.

    Replacing your line q = mp.Queue() with q = Queue.LifoQueue() and running prints: min, max and average as exactly -1.

    (Also I think you should always get exactly FIFO/LIFO order when getting items from only one thread.)

提交回复
热议问题