def writer(ring, start, count):
for i in range(start, start + count):
data = os.urandom(random.randint(1, 1000))
time_micros = int(time.time() * 10**6)
record = Record(
write_number=i,
timestamp_microseconds=time_micros,
length=len(data))
# Note: You can't pass 'data' to the constructor without doing an
# additional copy to convert the bytes type to a c_ubyte * 1000. So
# instead, the constructor will initialize the 'data' field's bytes
# to zero, and then this assignment overwrites the data-sized part.
record.data[:len(data)] = data
try:
ring.try_write(record)
except ringbuffer.WaitingForReaderError:
print('Reader is too slow, dropping %d' % i)
continue
if i and i % 100 == 0:
print('Wrote %d so far' % i)
ring.writer_done()
print('Writer is done')
评论列表
文章目录