我有一個消費者從我的生成器獲取數據。現在,消費者和發電機約需同一時間來處理,所以我總運行時間爲:緩衝區生成器
(t_generator + t_consumer) * number_of_items
我現在要運行,而我的消費過程中的當前項目的下一個項目發生器,使得我的消費者不必等待t_generator
這是如何在Python3中實現的?
EDIT(加小樣本):
g = my_generator() # cannot change this
intermediate = ??? # Do whatever you want. Maybe something like a queue which takes n from g and yields to consumer whenever ready?
processed p = consume(intermediate) # cannot change this
是發電機/消費者工作IO約束或CPU限制? –
發電機是CPU綁定和消費GPU綁定 –