tardis.utilities.asyncbulkcall module
- class tardis.utilities.asyncbulkcall.AsyncBulkCall(command: BulkCommand[T, R], size: int, delay: float, concurrent: Optional[int] = None)[source]
Bases:
Generic[T,R]Framework for queueing and executing several tasks via bulk commands
- Parameters
command – async callable that executes several tasks
size – maximum number of tasks to execute in one bulk
delay – maximum time window for tasks to execute in one bulk
concurrent – how often the command may be executed at the same time
Given some bulk-task callable
(T, ...) -> (R, ...)(thecommand),BulkExecutionrepresents a single-task callable(T) -> R. Single-task calls are buffered for a moment according tosizeanddelay, then executed in bulk withconcurrentcalls tocommand.Each
BulkExecutionshould represent a differentcommand(for example,rmormkdir) collecting similar tasks (for example,rm fooandrm bartorm foo bar). Thecommandis an arbitrary async callable and can freely decide how to handle its tasks. TheBulkExecutiontakes care of collecting individual tasks, partitioning them to bulks, and translating the results of bulk execution back to individual tasks.Both
sizeanddelaycontrol how long to queue tasks at most before starting to execute them. Theconcurrentparameter controls how many bulks may run at once; when concurrency is low tasks may be waiting for execution even pastsizeanddelay. Possible values forconcurrentareNonefor unlimited concurrency or an integer above 0 to set a precise concurrency limit.Note
If the
commandrequires additional arguments, wrap it viapartial(), for exampleAsyncBulkCall(partial(async_rm, force=True), ...).
- class tardis.utilities.asyncbulkcall.BulkCommand(*args, **kwargs)[source]
Bases:
Protocol[T,R]Protocol of callables suitable for
BulkExecutionA bulk command must take an arbitrary number of tasks and is expected to provide an iterable of one result per task. Alternatively, it may provide a single
Nonevalue to indicate that there is no result. An unhandledExceptionmeans that all tasks failed with thatException.