napari.qt.threading
Classes
QRunnable with signals that wraps a simple long-running function. |
|
QRunnable with signals that wraps a long-running generator. |
|
Base class for creating a Worker that can run in another thread. |
|
Functions
-
napari.qt.threading.active_thread_count()[source]¶ Return the number of active threads in the global ThreadPool.
- Return type
-
napari.qt.threading.create_worker(func, *args, _start_thread=None, _connect=None, _progress=None, _worker_class=None, _ignore_errors=False, **kwargs)[source]¶ Convenience function to start a function in another thread.
By default, uses
Worker, but a customWorkerBasesubclass may be provided. If so, it must be a subclass ofWorker, which defines a standard set of signals and a run method.- Parameters
func (Callable) – The function to call in another thread.
_start_thread (bool, optional) – Whether to immediaetly start the thread. If False, the returned worker must be manually started with
worker.start(). by default it will beFalseif the_connectargument isNone, otherwiseTrue._connect (Dict[str, Union[Callable, Sequence]], optional) – A mapping of
"signal_name"->callableor list ofcallable: callback functions to connect to the various signals offered by the worker class. by default None_progress (Union[bool, Dict[str, Union[int, bool, str]]], optional) – Can be True, to provide indeterminate progress bar, or dictionary. If dict, requires mapping of ‘total’ to number of expected yields. If total is not provided, progress bar will be indeterminate. Will connect progress bar update to yields and display this progress in the viewer. Can also take a mapping of ‘desc’ to the progress bar description. Progress bar will become indeterminate when number of yields exceeds ‘total’. By default None.
_worker_class (Type[WorkerBase], optional) – The :class`WorkerBase` to instantiate, by default
FunctionWorkerwill be used iffuncis a regular function, andGeneratorWorkerwill be used if it is a generator._ignore_errors (bool, optional) – If
False(the default), errors raised in the other thread will be reraised in the main thread (makes debugging significantly easier).*args – will be passed to
func**kwargs – will be passed to
func
- Returns
worker – An instantiated worker. If
_start_threadwasFalse, the worker will have a .start() method that can be used to start the thread.- Return type
- Raises
Examples
def long_function(duration): import time time.sleep(duration) worker = create_worker(long_function, 10)