Tôi muốn phân lớp multiprocessing.Queue để thực hiện các quy trình lấy khối của hàng đợi. Vấn đề duy nhất là, tôi nhận được một TypeError lạ?multiprocessing Queue subclass issue
#!/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)]
thử nghiệm này (tôi chia này ra vì vậy mà tôi đã không kéo trong bất cứ điều gì khác)
| => ./tests/wtf_queue.py
Traceback (most recent call last):
File "./tests/wtf_queue.py", line 10, in <module>
class BufferQueue(Queue):
TypeError: method expected 2 arguments, got 3
Chỉnh sửa/Cập nhật:
cách bạn khởi tạo hàng đợi? – eugecm
Tôi không. Những gì bạn thấy là toàn bộ bài kiểm tra. Tôi không thực sự gọi hoặc sử dụng nó theo bất kỳ cách nào. – SkyLeach
Tôi nghĩ rằng điều này có liên quan đến cách đa xử lý. Queue xử lý các tài nguyên cục bộ/chia sẻ? gọi đặc tả lớp trong khi JIT tải như một TypeDef có nghĩa là một cái gì đó trong lõi là nhận được munged AFAICT – SkyLeach