def __init__(self, size):
# The size of the queue is increased by one to give space for a QueueClosed signal.
size += 1
import multiprocessing.sharedctypes
# The condition variable is used to both lock access to the internal resources and signal new items are ready.
self.cvar = multiprocessing.Condition()
# A shared array is used to store items in the queue
sary = multiprocessing.sharedctypes.RawArray('b', 8*size)
self.vals = np.frombuffer(sary, dtype=np.int64, count=size)
self.vals[:] = -1
# tail is the next item to be read from the queue
self.tail = multiprocessing.sharedctypes.RawValue('l', 0)
# size is the current number of items in the queue. head = tail + size
self.size = multiprocessing.sharedctypes.RawValue('l', 0)
评论列表
文章目录