quantlab.factor.kunquant.shared_executor#
- quantlab.factor.kunquant.shared_executor(num_threads)[source]#
Return the process-wide KunQuant multi-thread executor for
num_threads.Every KunQuant run in quantlab takes its executor from here instead of calling
KunRunner.createMultiThreadExecutor. The first call for a thread count creates the executor; later calls return the same object, which lives until the interpreter exits.KunQuant’s executor destructor (kunquant 0.1.11) can miss its wake-up of a worker thread that is starting up or settling after a run; its
jointhen never returns, and since it holds the GIL the whole process freezes. So no executor is destroyed while the program runs: one per thread count is reused, and_release_executorsdestroys them at exit after the workers have settled.Reuse is safe because
runGraphandStreamContext.runwait until all their work is done before returning, so no work is left on the executor between runs. The idle worker threads of a cached executor wait on a condition variable and use no CPU.- Parameters:
- num_threadsint
Number of worker threads, as
FactorConfig.njobs.
- Returns:
- KunRunner.Executor
The cached executor for
num_threads.
Examples
>>> shared_executor(4) is shared_executor(4) True >>> shared_executor(4) is shared_executor(2) False