''Iterqueue'对象没有属性'not_full'

问题描述 投票:0回答:1

我有一个名为“ iterqueue”的课程,这是一个迭代队列:

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

i我搜索了此功能,因此我在自定义队列中实现了它,但什么也没有找到,

解决方案是什么?

python multiprocessing queue
1个回答
0
投票

您从
Queue
和Overrode
__init__
继承,但从未称为其
__init__,因此从来没有运行过。这意味着从未分配
not_full
,因此错误。 除非您要覆盖其0的默认参数,否则您只需要更改您的

maxsize

__init__
	

最新问题
© www.soinside.com 2019 - 2025. All rights reserved.