aqt.taskman#

Helper for running tasks on background threads.

See QueryOp() and CollectionOp() for higher-level routines.

Attributes#

Classes#

Module Contents#

aqt.taskman.Closure#
class aqt.taskman.TaskManager(mw: aqt.AnkiQt)#

Bases: QObject

mw#
run_on_main(closure: Closure) None#

Run the provided closure on the main thread.

run_in_background(task: collections.abc.Callable, on_done: collections.abc.Callable[[concurrent.futures.Future], None] | None = None, args: dict[str, Any] | None = None, uses_collection=True) concurrent.futures.Future#

Use QueryOp()/CollectionOp() in new code.

Run task on a background thread.

If on_done is provided, it will be called on the main thread with the completed future.

Args if provided will be passed on as keyword arguments to the task callable.

Tasks that access the collection are serialized. If you’re doing things that don’t require the collection (e.g. network requests), you can pass uses_collection =False to allow multiple tasks to run in parallel.

with_progress(task: collections.abc.Callable, on_done: collections.abc.Callable[[concurrent.futures.Future], None] | None = None, parent: QWidget | None = None, label: str | None = None, immediate: bool = False, uses_collection=True, title: str = 'Anki') None#

Use QueryOp()/CollectionOp() in new code.

with_backend_progress(task: collections.abc.Callable, progress_update: collections.abc.Callable[[anki.collection.Progress, aqt.progress.ProgressUpdate], None], on_done: collections.abc.Callable[[concurrent.futures.Future], None] | None = None, parent: QWidget | None = None, start_label: str | None = None, uses_collection=True) None#