Quantcast
Channel: Active questions tagged python - Stack Overflow
Viewing all articles
Browse latest Browse all 13921

Python queue keep only the latest element with specific condition

$
0
0

Let's say in the traditional producer/consumer pattern, the producer will produce two types of elements, A& B. The buffer queue should implement the following logics:

  • Thread safe.
  • FIFO
  • All A can safely stay in the queue, which denote important task.
  • Whenever a new B arrive, kick out all preceeding B in the queue and append to the end of the queue, which denote the latest non-important task.
  • The order of elements should be preserved.
  • The consumer pop element just like normal.

For simplicity, just imagine the size of the queue is unlimited.
Is it possible to implement this without using 2 queues?


Viewing all articles
Browse latest Browse all 13921

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>