Skip to content
Advertisement

Python check isinstance multiprocessing.Manager().Queue()

I am using python 2.7 multiprocessing on windows 7:

import multiprocessing as mp
from Queue import Queue
from multiprocessing.managers import AutoProxy

if __name__ == '__main__':
    manager = mp.Manager()
    myqueue = manager.Queue()

    print myqueue
    print type(myqueue)
    print isinstance(myqueue, Queue)
    print isinstance(myqueue, AutoProxy)

Output:

<Queue.Queue instance at 0x0000000002956B08>
<class 'multiprocessing.managers.AutoProxy[Queue]'>
False
Traceback (most recent call last):
  File "C:/Users/User/TryHere.py", line 12, in <module> print 
  isinstance(myqueue, AutoProxy) TypeError: isinstance() arg 2 must be a 
  class, type, or tuple of classes and types

My question is: I would like to check if a variable is an instance of a multiprocessing queue, how should i go about checking?

I have referred to:

Check for instance of Python multiprocessing.Connection?

Accessing an attribute of a multiprocessing Proxy of a class

but they dont seem to address my issue. Thanks in advance!

Advertisement

Answer

Question: I would like to check if a variable is an instance of a multiprocessing queue, how should i go about checking?

It’s a Proxy object, multiprocessing.managers.BaseProxy does match:

from multiprocessing.managers import BaseProxy
print(isinstance(myqueue, BaseProxy))
>>>True

Tested with Python: 3.4.2 and 2.7.9

User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement