Skip to content

Instantly share code, notes, and snippets.

@e-ruiz
Last active June 5, 2021 18:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save e-ruiz/c8230f76f5049883aab803327ff43095 to your computer and use it in GitHub Desktop.
Save e-ruiz/c8230f76f5049883aab803327ff43095 to your computer and use it in GitHub Desktop.
check CPU and determine some jobs
# python 3.7+
import multiprocessing
# CPUs disponíveis para esse processo
# @see: https://docs.python.org/3/library/os.html#os.cpu_count
# @see: https://docs.python.org/3/library/multiprocessing.html#multiprocessing.cpu_count
MAX_THREADS = multiprocessing.cpu_count()
# define um mínimo de 1 job e no máximo max_thread-2 jobs
JOBS = MAX_THREADS-2 if MAX_THREADS-2 > 1 else MAX_THREADS-2
print(f"MAX_THREADS: {MAX_THREADS}, JOBS: {JOBS}")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment