faster-fifo icon indicating copy to clipboard operation
faster-fifo copied to clipboard

Question

Open NikitaMishin opened this issue 3 years ago • 3 comments

Is size method thread(multi-process ) safe?

NikitaMishin avatar Aug 10 '22 09:08 NikitaMishin

And, will faster fifo queue faster be than mp queue in case many publishers single consumer?

NikitaMishin avatar Aug 11 '22 05:08 NikitaMishin

Is it possible to have several such queues? Would be there some deadlocks?

NikitaMishin avatar Aug 12 '22 09:08 NikitaMishin

Hi Nikita!

Is size method thread(multi-process ) safe?

qsize() is safe to call across threads and processes but it only gives you an approximation of the number of messages. I recommend using it only for diagnostic/logging purposes and not to make decisions. It's semantics is similar to standard multiprocessing.Queue https://docs.python.org/3/library/multiprocessing.html#multiprocessing.Queue.qsize

This means that you have to be careful with code like this:

if q.qsize() > 0:
    # another process can change the queue size here
    do something important ...

And, will faster fifo queue faster be than mp queue in case many publishers single consumer?

In this scenario you should get the most gains especially if you use get_many()

Is it possible to have several such queues? Would be there some deadlocks?

I have 100+ queues in some of my applications. So yes, you can have many queues per process, per thread and across processes/threads.

alex-petrenko avatar Aug 12 '22 18:08 alex-petrenko