I am using python 2.7 multiprocessing on windows 7:
JavaScript
x
13
13
1
import multiprocessing as mp
2
from Queue import Queue
3
from multiprocessing.managers import AutoProxy
4
5
if __name__ == '__main__':
6
manager = mp.Manager()
7
myqueue = manager.Queue()
8
9
print myqueue
10
print type(myqueue)
11
print isinstance(myqueue, Queue)
12
print isinstance(myqueue, AutoProxy)
13
Output:
JavaScript
1
8
1
<Queue.Queue instance at 0x0000000002956B08>
2
<class 'multiprocessing.managers.AutoProxy[Queue]'>
3
False
4
Traceback (most recent call last):
5
File "C:/Users/User/TryHere.py", line 12, in <module> print
6
isinstance(myqueue, AutoProxy) TypeError: isinstance() arg 2 must be a
7
class, type, or tuple of classes and types
8
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:
JavaScript
1
4
1
from multiprocessing.managers import BaseProxy
2
print(isinstance(myqueue, BaseProxy))
3
>>>True
4
Tested with Python: 3.4.2 and 2.7.9