dcnum.os_env_st

Attributes

os_env_threading

environment variables that define number of threads libraries will use

Classes

RequestSingleThreaded

Context manager for starting a process with specific environment

Functions

confirm_single_threaded()

Warn via logs when environment variables are not set to single thread

request_single_threaded()

Set the environment variable to single thread

Module Contents

dcnum.os_env_st.os_env_threading = ['MKL_NUM_THREADS', 'NUMBA_NUM_THREADS', 'NUMEXPR_NUM_THREADS', 'NUMPY_NUM_THREADS',...

environment variables that define number of threads libraries will use

class dcnum.os_env_st.RequestSingleThreaded[source]

Context manager for starting a process with specific environment

When entering the context, the environment variables defined in os_env_threading are all set to “1”, telling the relevant libraries that they should work in single-threaded mode. When exiting the context, these environment variables are reset to their original values (or unset if applicable).

Note that it makes only sense to use this context manager when starting new multiprocessing processes. When the process spawns, the environment from the current thread is copied. Setting the environment variable after e.g. importing numpy has no effect on how many threads numpy will use.

previous_env
__enter__()[source]

Ask nicely for single-threaded computation using os.environ

Note that this only affects new processes in which the relevant libraries have not yet been imported.

__exit__(type, value, traceback)[source]

Restore the previous environment

dcnum.os_env_st.confirm_single_threaded()[source]

Warn via logs when environment variables are not set to single thread

dcnum.os_env_st.request_single_threaded()[source]

Set the environment variable to single thread

This function must be called before importing the multithreaded libraries (such as numpy) in order for them to pick up the environment variables.