duck.utils.threading¶
Threading utilities and helpers.
Submodules¶
Package Contents¶
Classes¶
A thread-safe future that blocks until a result is set or an exception is raised. |
Functions¶
Converts an asynchronous future to a synchronous future. |
|
Dynamically calculate a safe max_workers value for ThreadPoolExecutor, based on CPU count, available memory, stack size, and current system usage. Works cross-platform (Linux, Windows, macOS). No root required. |
API¶
- class duck.utils.threading.SyncFuture[source]¶
A thread-safe future that blocks until a result is set or an exception is raised.
This class mimics a subset of the behavior of asyncio.Future, but for use in synchronous (threaded) code. It allows one thread to wait for a value or error that will be provided by another thread.
Initialization
Initializes the SyncFuture with no result or exception.
- result()[source]¶
Blocks until a result or exception is set, then returns or raises it.
- Returns:
The result value previously set by
set_result().- Return type:
Any
- Raises:
Exception – If an exception was set using
set_exception().
- duck.utils.threading.async_to_sync_future(async_future: asyncio.Future) SyncFuture[source]¶
Converts an asynchronous future to a synchronous future.
- duck.utils.threading.get_max_workers() int[source]¶
Dynamically calculate a safe max_workers value for ThreadPoolExecutor, based on CPU count, available memory, stack size, and current system usage. Works cross-platform (Linux, Windows, macOS). No root required.
- Returns:
Suggested max_workers value (min 8, max 2000)
- Return type:
int