pythonmultiprocessingqueue

'IterQueue' object has no attribute 'not_full'


I have a class called "IterQueue which is an iter queue:

IterQueue.py

from multiprocessing import Process, Queue, Pool
import queue

class IterQueue(queue.Queue):

def __init__(self):
    self.current = 0
    self.end = 10000

def __iter__(self):
    self.current = 0
    self.end = 10000
    while True:
        yield self.get()

def __next__(self):
    if self.current >= self.end:
        raise StopIteration
    current = self.current
    self.current += 1
    return current

I put items inside it in a different processes:

modulexxx.py

...
self.q1= IterQueue()

def function(self):

    x = 1
    while True:
        x = x + 1
        self.q1.put(x)

Everything works fine, but python gives me an error:

'IterQueue' object has no attribute 'not_full

I searched for this function so I implement it in my custom queue, but found nothing,

What's the solution to this ?


Solution

  • You inherited from Queue and overrode __init__, but never called its __init__, so that was never run. That means that not_full was never assigned, thus the error.

    Unless you want to override its maxsize default argument of 0, you just need to change your __init__ to:

    def __init__(self):
        super().__init__()
        self.current = 0
        self.end = 10000