I wanted to implement multiprocessing priorityqueue . I found this answer :- Strange Queue.PriorityQueue behaviour with multiprocessing in Python 2.7.6
by Dano
After I implemented this . I could use .get() and .put() function for my Priority Queue but when i used .queue to print the current elements in the queue it gave me an error
code:-
class MyManager(SyncManager):
pass
def get_manager():
MyManager.register("PriorityQueue", PriorityQueue) # Register a shared PriorityQueue
m = MyManager()
m.start()
return m
m = get_manager()
call= m.PriorityQueue()
for i in range(5):
call.put(i)
print(call.queue)
Error : AttributeError: 'AutoProxy[PriorityQueue]' object has no attribute 'queue'
I read the python documentation for SyncManager and modified my code .
New code :-
class MyManager(SyncManager):
pass
def get_manager():
MyManager.register("PriorityQueue", PriorityQueue,exposed=['put','get','queue']) # Register a shared PriorityQueue
m = MyManager()
m.start()
return m
m = get_manager()
call= m.PriorityQueue()
for i in range(5):
call.put(i)
print(call.queue)
Now output was :-
<bound method AutoProxy[PriorityQueue].queue of <AutoProxy[PriorityQueue] object, typeid 'PriorityQueue' at 0x7ff3b48f2dd0>>
I am still not getting the elements in the queue , i read about method_to_typeid
attribute of register function to map the return type of functions mentioned in exposed
, but i don't know how use that .
Can someone help me with this , so that i could print elements of the queue without poping them from queue