naturtag.app.threadpool module¶
Adapted from examples in Python & Qt6 by Martin Fitzpatrick
- class naturtag.app.threadpool.BaseWorker(callback, **kwargs)¶
Bases:
QRunnableBase for all worker types. Subclasses must emit
on_finishedas their very last signal emission inrun().
- class naturtag.app.threadpool.PaginatedWorker(callback, **kwargs)¶
Bases:
BaseWorkerA worker thread that specifically handles paginated requests via iNatClient/iNatDbClient
- run()¶
- class naturtag.app.threadpool.ProgressBar(**kwargs)¶
Bases:
QProgressBarShared progress bar, updated by ThreadPool
- add(amount=1)¶
- advance(amount=1)¶
- fadein()¶
- fadeout()¶
- remove(amount)¶
Decrease maximum by
amountto account for cancelled tasks.
- reset()¶
- schedule_reset()¶
After a delay, if no new tasks have been added, reset and hide the progress bar
- staticMetaObject = PySide6.QtCore.QMetaObject("ProgressBar" inherits "QProgressBar": Methods: #40 type=Slot, signature=add(int), parameters=int #41 type=Slot, signature=advance(int), parameters=int )¶
- class naturtag.app.threadpool.ThreadPool(num_workers=0, **kwargs)¶
Bases:
QThreadPoolThread pool that enqueues jobs to ber run from separate thread(s), and updates a progress bar.
- cancel(group=None)¶
Cancel queued tasks and adjust the progress bar. Currently running tasks will be allowed to complete.
- Parameters:
group (
str|None) – If provided, only cancel tasks in this group. Otherwise cancel all tasks.
- schedule(callback, priority=Priority.NormalPriority, total_results=None, increment_length=False, group=None, **kwargs)¶
Schedule a task to be run by the next available worker thread
- Return type:
- schedule_paginator(callback, priority=Priority.NormalPriority, total_results=None, group=None, **kwargs)¶
Schedule a task to be run by the next available worker thread
- Return type:
- staticMetaObject = PySide6.QtCore.QMetaObject("ThreadPool" inherits "QThreadPool": )¶
- class naturtag.app.threadpool.Worker(callback, increment_length=False, **kwargs)¶
Bases:
BaseWorkerA worker thread that takes a callback (and optional args/kwargs), and updates progress when done.
- run()¶
- class naturtag.app.threadpool.WorkerSignals¶
Bases:
QObjectSignals used by a worker thread (can’t be set directly on a QRunnable)
- on_complete¶
Emitted when the worker has finished all work
- on_error¶
Return exception info on error
- on_finished¶
Always the last signal emitted; used for lifecycle cleanup
- on_progress¶
Increment progress bar
- on_result¶
Return result on completion
- on_result_total¶
Return total results
- staticMetaObject = PySide6.QtCore.QMetaObject("WorkerSignals" inherits "QObject": Methods: #4 type=Signal, signature=on_error(PyObject), parameters=PyObject #5 type=Signal, signature=on_result_total(int), parameters=int #6 type=Signal, signature=on_result(PyObject), parameters=PyObject #7 type=Signal, signature=on_progress(int), parameters=int #8 type=Signal, signature=on_complete() #9 type=Signal, signature=on_finished() )¶