Q:

Is there anything like a Python JoinableDeque available?

I'm relatively new to Python and looking for something like Python's JoinableQueue, but that has deque or stack-like behavior.  Specifically, as I'm processing items in the queue in different processes, I'd like to be able to add new items to be processed before what's already in the queue (i.e. push onto the stack or add to the front of the deque). Java has BlockingDeque which does exactly what I want, but I can't really use Java for this project. Any pointers or new ways of thinking about this problem would be appreciated!

A:

With multiprocessing, queue semantics isn't just something implemented on top of inter-process communication but is inherent to it. Therefore, the simplest solution is probably to build a joinable stack by using a JoinableQueue and implementing pushes to the stack by first getting all tasks into a temporary queue, then queueing the new element and filling back the tasks from the temporary queue. Pushing to the stack from different processes would require some locking to maintain the order of the stack.

