9

I have two python classes that share a base class that let's say defines a multiprocessing.Queue.

Each of those classes will be launched on a separate subprocess and need to share info through a queue.

Now, if the base class defines a Queue, then each subclass object will instantiate it's own queue, making the sharing of queue elements impossible. But then again I find this documented

Queue objects should only be shared between processes through inheritance. 

So what's the proper way of sharing a Queue between subprocesses and how does the above sentence even make sense?

Note that I can obviously pass a reference to the queue at initialization of the subprocesses but I'd like to takle this problem using inheritance

sophros
  • 14,672
  • 11
  • 46
  • 75
Kam
  • 5,878
  • 10
  • 53
  • 97
  • 1
    Can you give an example of code exhibiting the issue? I've quickly read a few things about this and I think by inheritance they mean inheritance from a parent process (if so its definitely confusing). I found some examples using `multiprocessing.Manager` to avoid the error. – Paul Rooney Jan 18 '16 at 04:46
  • 1
    See [here](https://docs.python.org/3.5/library/multiprocessing.html#shared-ctypes-objects). quote: *It is possible to create shared objects using shared memory which can be inherited by child processes*. – Paul Rooney Jan 18 '16 at 04:49
  • I think the confusion is the word `inheritance`. They mean inheritance between processes, and not classes. – Mahdi Jul 11 '17 at 15:26

1 Answers1

1

So what's the proper way of sharing a Queue between subprocesses and how does the above sentence even make sense?

The sentence makes sense when you are talking about inheritance between processes, like child and parent processes. It is NOT about classes and inheritance in Object Oriented Programming.


For the proper way of using queues, look at this or this for example.

Mahdi
  • 1,778
  • 1
  • 21
  • 35