rheon.thread_pool_size

rheon.thread_pool_size(*, threads: int | None = None) → int[source]

The number of threads a bank given this threads argument runs on.

Use it to see how many threads a bank will use before you build one, or what RHEON_MAX_THREADS gives. Polars’ own threads are separate, set by POLARS_MAX_THREADS, and pl.thread_pool_size() reports those.

Parameters

threads

The count a bank would be given, as ModelBank takes it. None, the default, names the process’s shared threads, which every bank given no threads runs on. RHEON_MAX_THREADS sets their number when they are first used (unset or 0: one thread per core), and the number never changes after that. This call starts them if nothing has yet. An integer n names n threads, which this call checks without starting them.

Returns

int: the number of threads.

Raises

TypeError

threads is not an integer, a bool included.

ValueError

threads is below 1, or above 1024 (or the machine’s core count, where that is larger); or threads is None and RHEON_MAX_THREADS is set to anything but a whole number, or to a count past the same bound. More threads than cores run no faster, and a pool starts all of its threads at once. A bank refuses the same values: a threads when it is made, and a bad RHEON_MAX_THREADS at its first call that runs. Both are checked before any thread starts.

Examples

print(rp.thread_pool_size(threads=2))   # 2: checked, and no thread starts
2

See also

  • ModelBank, whose threads argument this reads.