Guest User

Untitled

a guest
May 25th, 2018
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.10 KB | None | 0 0
  1. def set_max_job_count(env, count = 0):
  2. """
  3. Sets the max job count for SCons execution.
  4. If count == 0 then we determine the number of CPU's on the system
  5. and sets the maximum job count accordingly.
  6. """
  7. def get_cpu_nums():
  8. """
  9. Detects the number of CPUs on a system.
  10. """
  11. # Linux, Unix and MacOS:
  12. if hasattr(os, "sysconf"):
  13. if os.sysconf_names.has_key("SC_NPROCESSORS_ONLN"):
  14. # Linux & Unix:
  15. ncpus = os.sysconf("SC_NPROCESSORS_ONLN")
  16. if isinstance(ncpus, int) and ncpus > 0:
  17. return ncpus
  18. else: # OSX:
  19. return int(os.popen2("sysctl -n hw.ncpu")[1].read())
  20. # Windows:
  21. if os.environ.has_key("NUMBER_OF_PROCESSORS"):
  22. ncpus = int(os.environ["NUMBER_OF_PROCESSORS"]);
  23. if ncpus > 0:
  24. return ncpus
  25. return 1 # Default
  26. job_count = get_cpu_nums() if not count else count
  27. print "scons: Max %d parallel jobs" % job_count
  28. env.SetOption("num_jobs", job_count)
Add Comment
Please, Sign In to add comment