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
),BulkExecution
represents a single-task callable(T) -> R
. Single-task calls are buffered for a moment according tosize
anddelay
, then executed in bulk withconcurrent
calls tocommand
.Each
BulkExecution
should represent a differentcommand
(for example,rm
ormkdir
) collecting similar tasks (for example,rm foo
andrm bar
torm foo bar
). Thecommand
is an arbitrary async callable and can freely decide how to handle its tasks. TheBulkExecution
takes care of collecting individual tasks, partitioning them to bulks, and translating the results of bulk execution back to individual tasks.Both
size
anddelay
control how long to queue tasks at most before starting to execute them. Theconcurrent
parameter controls how many bulks may run at once; when concurrency is low tasks may be waiting for execution even pastsize
anddelay
. Possible values forconcurrent
areNone
for unlimited concurrency or an integer above 0 to set a precise concurrency limit.Note
If the
command
requires additional arguments, wrap it viapartial()
, for exampleAsyncBulkCall(partial(async_rm, force=True), ...)
.
- class tardis.utilities.asyncbulkcall.BulkCommand(*args, **kwds)[source]
Bases:
Protocol
[T
,R
]Protocol of callables suitable for
BulkExecution
A 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
None
value to indicate that there is no result. An unhandledException
means that all tasks failed with thatException
.