代码之家  ›  专栏  ›  技术社区  ›  Mohammed Baashar

“IterQueue”对象没有属性“not_full”

  •  1
  • Mohammed Baashar  · 技术社区  · 10 月前

    我有一个名为“IterQueue”的类,它是一个iter队列:

    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
    

    我以不同的流程将项目放入其中:

    modulexxx.py

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

    一切正常,但python给了我一个错误:

    'IterQueue' object has no attribute 'not_full
    

    我搜索了这个函数,所以在我的自定义队列中实现了它,但什么也没找到,

    解决这个问题的办法是什么?

    1 回复  |  直到 10 月前
        1
  •  2
  •   Carcigenicate    10 月前

    你继承自 Queue 并覆盖 __init__ ,但从未称之为 __init__ ,所以它从未运行过。这意味着 not_full was never assigned 因此,错误。

    除非你想覆盖它 maxsize 默认参数为0,您只需更改 __init__ 致:

    def __init__(self):
        super().__init__()
        self.current = 0
        self.end = 10000
    
    推荐文章