python - 'JoinableQueue' object is not iterable -
assuming have queue:
myqueue = multiporcessing.joinablequeue() in code, parent process puts object (e.g. string) myqueue, 'myqueue' shared kid processes, , kid process need check if object (e.g. xxx) in myqueue, tried use:
if xxx in [y y in myqueue] but gives me error like:
'joinablequeue' object not iterable my question is, there other way can utilize want above? or way can utilize check if object still in queue?
the reason checking shared queue objects in queue interdependence, , every object has status such 'running', 'waiting', 'completed'. example, object 'a' has dependency 'a', 'a' , 'a' set queue parent process(before kid process kick-off), when kid process gets 'a' queue, needs check status of 'a', if status of 'a' still 'waiting', 'a' set queue unless 'a' 'completed'. in other words, 'a' not in myqueue anymore.
joinablequeue doesn't back upwards peeking of kind (unless count empty/full).
depending on want collection in addition, need different object store queue in. however, there 2 possible solutions:
if know no other process touch queue while checking this, get every object, see if looking there, put them in same order.
otherwise, if kid process ever get objects, set objects in temporary queue.
the former should straightforward implement. latter like:
class queueview: def __init__(self, joinable): self.joinable = joinable self.other = collections.deque() def get(self, block=true, timeout=none): if self.other: homecoming self.other.popleft() self.joinable.get(block, timeout) def __contains__(self, item): if item in self.other: homecoming true try: while true: o = self.joinable.get(block=false) self.other.append(o) except queue.empty: pass homecoming item in self.other only 1 process should see queueview object , get joinablequeue through view object. number of processes can put things in joinablequeue.
python for-loop queue multiprocessing
No comments:
Post a Comment