AsyncExecutor¶
- class chancy.executors.asyncex.AsyncExecutor(worker, queue)[source]¶
Bases:
ExecutorAn 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
executorfield of your queue configuration or use theExecutorshortcut:async with Chancy("postgresql://localhost/postgres") as chancy: await chancy.declare( Queue( name="default", executor=Chancy.Executor.Async, ) )
- async cancel(ref)[source]¶
Attempt to cancel every running execution of the referenced 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 (Reference) – The reference to the job to cancel.
- async cancel_execution(job)[source]¶
Attempt to cancel only the execution identified by
job.claim_id.Recovery uses this optional hook instead of job-wide cancellation. Custom executors must match both the job ID and claim ID. The default does nothing; database fencing still rejects the abandoned execution’s updates when cancellation is unsupported or unsuccessful.
- Parameters:
job (QueuedJob)
- get_default_concurrency()[source]¶
Get the default concurrency level for this executor.
This method is called when the queue’s concurrency level is set to None. It should return the number of jobs that can be processed concurrently by this executor.
By default, returns 100.