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