python实现队列问题_python-3.x – 多处理队列子类问题

我想将multiprocessing.Queue子类化,以实现抓取队列块的进程.唯一的问题是,我得到一个奇怪的TypeError?

#!/usr/bin/env python

#whaaaaa!?

from multiprocessing import Queue

class BufferQueue(Queue):

'''A thread/process safe queue for append/popleft operations with the import

buffer.'''

def __init__(self,**kwargs):

super(BufferQueue,self).__init__(**kwargs)

def consume(self,lim):

'''Consume up to but no more than lim elements and return them in a new

list,cleaning up the buffer.

@params

lim -- the maximum (limit) to consume from the list. If less items

exist in the list then that's fine too.

'''

lim = len(queue) if len(queue) < lim else lim

return [self.popleft() for i in range(lim)]

测试这个(我将其拆分,以便我不会拉其他任何东西)

| => ./tests/wtf_queue.py

Traceback (most recent call last):

File "./tests/wtf_queue.py",line 10,in

class BufferQueue(Queue):

TypeError: method expected 2 arguments,got 3

编辑/更新:

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值