0

I am using the multiprocessing library. I would like to use a Queue-like object (meaning that it can be shared and read between processes safely) that always exposes the latest value written inside. I would like to do so without consuming the value so other processes can read the value as well.

I'm taking the example of the Queue because I only know about Pipes and Queues, but the previous values do not need to be kept like they do in those. They can be discarded.

>>> q = MyIdealQueue()
>>> q.put(0)
>>> q.put(1)
>>> q.get()
1
>>> q.get()
1
>>> q.put(2)
>>> q.get()
2

Maybe shared memory is the way to go ?

Leogout
  • 1,187
  • 1
  • 13
  • 32
  • Sounds more LIFO, i.e. a stack. – Booboo Sep 19 '20 at 11:30
  • 1
    So you want `get()` to not consume the value and `put()` to replace the previous value? Sounds like you just want a shared variable. `get()` gets the value, `put()` changes the value. Maybe [this](https://stackoverflow.com/a/17393879/9568847) solves your problem? – Niklas Mertsch Sep 19 '20 at 11:48
  • 1
    Yeah I've tried with a Manager() to share a dict and that works perfectly, thanks. – Leogout Sep 19 '20 at 12:07

0 Answers0