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.
Return the number of active threads in the global ThreadPool.
- Return type
create_worker(func, *args, _start_thread=None, _connect=None, _worker_class=None, _ignore_errors=False, **kwargs)¶
Convenience function to start a function in another thread.
By default, uses
Worker, but a custom
WorkerBasesubclass may be provided. If so, it must be a subclass of
Worker, which defines a standard set of signals and a run method.
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 be
_connect (Dict[str, Union[Callable, Sequence]], optional) – A mapping of
callableor list of
callable: callback functions to connect to the various signals offered by the worker class. by default None
_worker_class (Type[WorkerBase], optional) – The :class`WorkerBase` to instantiate, by default
FunctionWorkerwill be used if
funcis a regular function, and
GeneratorWorkerwill 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
**kwargs – will be passed to
worker – An instantiated worker. If
False, the worker will have a .start() method that can be used to start the thread.
- Return type
def long_function(duration): import time time.sleep(duration) worker = create_worker(long_function, 10)
Set the maximum number of threads used by the thread pool.
Note: The thread pool will always use at least 1 thread, even if maxThreadCount limit is zero or negative.