bunpy.queue
import bunpy.queue as queueCreating a queue
q = queue.Queue(concurrency=4)concurrency sets the number of goroutines processing tasks in parallel.
Enqueuing tasks
q.push(my_function, arg1, arg2)
q.push(another_function)Waiting for completion
q.wait() # blocks until all queued tasks completeError handling
If a task raises an exception, the error is recorded and all remaining tasks
are still processed. After wait(), check:
errors = q.errors()
if errors:
for err in errors:
print(err)Example
import bunpy.queue as queue
results = []
def process(item):
results.append(item * 2)
q = queue.Queue(concurrency=8)
for i in range(100):
q.push(process, i)
q.wait()
print(sorted(results)[:5]) # [0, 2, 4, 6, 8]