pyfunctools.decorators.threaded_decorator module
- no-index:
- pyfunctools.decorators.threaded_decorator.threaded_decorator(func)[source]
A decorator to run a function in a separate thread.
This decorator uses a ThreadPoolExecutor to run the decorated function in a separate thread, allowing for concurrent execution.
- Parameters:
func (callable) – The function to be decorated.
- Returns:
A function that runs the original function in a thread.
- Return type:
callable
Example
>>> @threaded_decorator ... def slow_function(x): ... import time ... time.sleep(2) ... return x * 2 >>> >>> print(slow_function(5)) 10