Search code examples
pythonmultithreadingprocessfpugil

Can the FPU rounding mode set from a Python process be altered by another Python process?


I use much the libqd library which requires setting the FPU rounding mode before any computation. Until now I was mainly using it in C programs but I would like to use it from Python scripts from time to time.

I heard about the global interpreter lock (GIL) which is described at https://wiki.python.org/moin/GlobalInterpreterLock or in the answer to this question same python interpreter instance running multiple scripts simultaneously?

In the first of these two pages, I can read: "The GIL is controversial because it prevents multithreaded CPython programs from taking full advantage of multiprocessor systems in certain situations."

Thus I wonder whether a very long computation (several days for instance) could be disturbed by another Python program running on the same machine: could it happen that the FPU rounding mode would be changed by another process during the computation?


Solution

  • No, the GIL is per-process. You're running a seperate interpreter per each process. The operating system should make sure different processes can't affect each other.

    The linked question suggests that the operating system may share some memory between these different processes, but only memory that's the same in both.