0

Is it is possible to set or limit the number of cores a python script can use in the terminal?

I'm not familiar with multicore processing in python but I know there is a simple way to do this in Julia. You can create a REPL using 4 cores by typing julia --procs=4. I was wondering if there exists something similar in python, kind of like python --n_cores=4 python_script.py.

Kilian
  • 1
  • as I know Python normally uses only one thread so it uses only one core - so it doesn't need this option. And if you use modules like `threading`/`processing` then they may have (in object `Pool`) option how many threads/processes to use at the same time. But if you use Linux then you may try to use external program [cpulimit](https://manpages.ubuntu.com/manpages/xenial/man1/cpulimit.1.html) to run any program with some limits on CPU. like `cpulimit --cpu 4 python script.py` (but it didn't tested it with Python, only with `ffmpeg` when I have to compress long video) – furas May 24 '22 at 11:36
  • [How to limit number of CPU's used by a python script w/o terminal or multiprocessing library? - Stack Overflow](https://stackoverflow.com/questions/55746872/how-to-limit-number-of-cpus-used-by-a-python-script-w-o-terminal-or-multiproces) – furas May 24 '22 at 11:42

0 Answers0