Ensure that there is a warm thread pool. With num_workers=None on the default thread, this function warms up the default thread pool. With num_workers set or from a different thread, this function spawns and warms up a non-default thread pool. When this function is called after ano
(num_workers: int | None)
| 203 | |
| 204 | |
| 205 | def warm_up_thread_pool(num_workers: int | None) -> None: |
| 206 | """Ensure that there is a warm thread pool. |
| 207 | |
| 208 | With num_workers=None on the default thread, this function warms up the default |
| 209 | thread pool. With num_workers set or from a different thread, this function spawns |
| 210 | and warms up a non-default thread pool. |
| 211 | |
| 212 | When this function is called after another test that called get() or compute(), the |
| 213 | thread pool will be already warm, at least partially (not all threads will |
| 214 | necessarily be already running). |
| 215 | """ |
| 216 | parties = num_workers or CPU_COUNT |
| 217 | barrier = threading.Barrier(parties) |
| 218 | dsk = {("x", i): (barrier.wait,) for i in range(parties)} |
| 219 | get(dsk, list(dsk), num_workers=num_workers) |
| 220 | |
| 221 | |
| 222 | test_ctxvar = contextvars.ContextVar("test_ctxvar", default=42) |
no test coverage detected