Dex.ThreadPool¶
- Subclasses:
None
Methods¶
- Inherited:
class |
|
|
|
|
Virtual Methods¶
None
Fields¶
None
Class Details¶
- class Dex.ThreadPool¶
- Bases:
- Abstract:
No
DexThreadPoolis a thread pool for managing native OS threads similar to [struct`GLib`.ThreadPool].The threads managed by
DexThreadPooldo not contain a [class`Dex`.Scheduler] which means that you cannot await futures or schedule [class`Dex`.Block] from a worker thread.Threads are created up-front from [ctor`Dex`.ThreadPool.new].
DexThreadPoolprimarily exists for situations where you are using blocking external libraries and want to avoid calling [func`Dex`.thread_spawn] without any sort of queuing or bounding on the permitted concurrency.Added in version 1.2.
- classmethod new(n_threads)¶
- Parameters:
n_threads (
int) – the number of threads to create- Returns:
a new
DexThreadPool- Return type:
Creates a fixed-size pool of reusable operating system threads.
Added in version 1.2.
- close(mode)¶
- Parameters:
mode (
Dex.ThreadPoolShutdownMode) – shutdown policy for queued work- Returns:
a future that resolves when shutdown completes
- Return type:
Begins shutting down the pool and prevents new submissions.
- get_n_threads()¶
- Returns:
the number of threads in the pool
- Return type:
Gets the fixed number of threads owned by the pool.
Added in version 1.2.
- submit(thread_name, thread_func, *user_data)¶
- Parameters:
thread_name (
strorNone) – the name to use for debugging the returned futurethread_func (
Dex.ThreadFunc) – the function to run on a pooled thread
- Returns:
a future that resolves when the work completes
- Return type:
Queues blocking work to run on one of the pool’s reusable threads.
The provided thread_name is applied to the returned future using
dex_future_set_static_name()so that tracing and debugging tools can identify the work item. It does not rename the underlying OS worker thread.Added in version 1.2.