如果我想创建一个带有边界的队列,但是我想为函数内部的队列创建边界而不是使用Class BoundedQueue.Queue(maxsize = 4),该怎么办? (关于最大绑定队列的信息:http://docs.python.org/2/library/queue.html)python中的有界队列
有什么建议吗?
这是我的代码; capacity
是最大的界限。
class BoundedQueue:
# Constructor, which creates a new empty queue, with user-specified capacity:
def __init__(self, capacity):
self.items = []
assert(capacity >= 0), "not positive"
try:
capacity = int(capacity)
except TypeError as inst:
print("Error", inst.args)
except:
print("error")
else:
itemmax = capacity
你准确的问题是什么?不知道我关注 – Crisfole 2013-02-12 21:42:59
我不确定你的实际问题在这里。通过“为函数内部的队列创建边界”,你的意思是容量是变量而不是文字值?标准的'Class BoundedQueue.Queue(maxsize = capacity)'不应该在这里工作。 – 2013-02-12 21:43:14
[deque](http://docs.python.org/2/library/collections.html#collections.deque)可以由maxlen限制 - 它足够吗? – sotapme 2013-02-12 21:46:55