AsyncExecutor

class chancy.executors.asyncex.AsyncExecutor(worker, queue)[source]

Bases: Executor

An Executor which uses asyncio to run its jobs in the main event loop.

This executor is useful for running large numbers of IO-bound jobs, as it can run many jobs concurrently without blocking the main event loop and without the high overhead of new processes or threads. However, it is not suitable for CPU-bound jobs, as it will block the main event loop and prevent other jobs & queues from running.

To use this executor, simply pass the import path to this class in the executor field of your queue configuration or use the Executor shortcut:

async with Chancy("postgresql://localhost/postgres") as chancy:
    await chancy.declare(
        Queue(
            name="default",
            executor=Chancy.Executor.Async,
        )
    )
async cancel(ref: Reference)[source]

Attempt to cancel a running job.

It’s not guaranteed that the job will be cancelled, as it may have already completed by the time this method is called or the executor may not support cancellation.

Parameters:

ref – The reference to the job to cancel.

async push(job: QueuedJob)[source]

Push a job onto the job pool.

async stop()[source]

Stop the executor, giving it a chance to clean up any resources it may have allocated to running jobs.