Reference

Defines tools for simplifying the use of asynchronous Python.

class fsc.async_tools.PeriodicTask(task_func, *, loop=None, delay=1.0, run_on_exit=True)[source]

Asynchronous context manager that periodically runs a given function.

Parameters:
  • loop (EventLoop) – The event loop on which the tasks are executed. Uses asyncio.get_event_loop() if no event loop is specified.
  • task_func (Callable) – The function which is executed. It cannot take any arguments, and must not be a coroutine.
  • delay (float) – The minimum time between running two calls to the function.
  • run_on_exit (bool) – Determines if the function should be run again when exiting the context manager.
fsc.async_tools.wrap_to_coroutine(func)[source]

Wraps a function or coroutine into a coroutine.

Parameters:func (Callable) – The function or coroutine that should be wrapped.
class fsc.async_tools.BatchSubmitter(func, *, loop=None, timeout=0.1, sleep_time=0.0, wait_batch_size=None, max_batch_size=1000)[source]

Function wrapper that collects calls to a function of one parameter, and submits it in batches to a function which can take a list of parameters.

Parameters:
  • func (Callable) – Function or coroutine which is “listable”, i.e. given a list of input parameters it will return a list of results.
  • loop (EventLoop) – The event loop on which the batch submitter runs. Uses asyncio.get_event_loop() by default.
  • timeout (float) – Maximum time after which the batch submitter will submit all current tasks, even if the minimum batch size is not reached.
  • sleep_time (float) – Time the batch submitter will sleep between checking if the minimum batch size has been reached.
  • wait_batch_size (int) – Minimum batch size that will be submitted before the timeout has been reached. Is set to the same value as max_batch_size unless specified explicitly.
  • max_batch_size (int) – The maximum size of a batch that will be submitted.
fsc.async_tools.limit_parallel(max_num_parallel)[source]

Decorator that limits the number of parallel calls to a function or coroutine.

Parameters:max_num_parallel (int) – The maximum number of calls which can run in parallel.