dcnum.os_env_st =============== .. py:module:: dcnum.os_env_st Attributes ---------- .. autoapisummary:: dcnum.os_env_st.os_env_threading Classes ------- .. autoapisummary:: dcnum.os_env_st.RequestSingleThreaded Functions --------- .. autoapisummary:: dcnum.os_env_st.confirm_single_threaded dcnum.os_env_st.request_single_threaded Module Contents --------------- .. py:data:: os_env_threading :value: ['MKL_NUM_THREADS', 'NUMBA_NUM_THREADS', 'NUMEXPR_NUM_THREADS', 'NUMPY_NUM_THREADS',... environment variables that define number of threads libraries will use .. py:class:: RequestSingleThreaded 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. .. py:attribute:: previous_env .. py:method:: __enter__() 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. .. py:method:: __exit__(type, value, traceback) Restore the previous environment .. py:function:: confirm_single_threaded() Warn via logs when environment variables are not set to single thread .. py:function:: request_single_threaded() 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.