code: def _available_cpu_count():
      
      try:
          return len(os.sched_getaffinity(0))
      except AttributeError:
          pass
      import re
      try:
          with open('/proc/self/status') as f:
              status = f.read()
          m = re.search(r'(?m)^Cpus_allowed:\s*(.*)$', status)
          if m:
              res = bin(int(m.group(1).replace(',', ''), 16)).count('1')
              if res > 0:
                  return res
      except IOError:
          pass
      try:
          import multiprocessing
          return multiprocessing.cpu_count()
      except (ImportError, NotImplementedError):
          return 1
docs: Number of available virtual or physical CPUs on this system
      Adapted from http://stackoverflow.com/a/1006301/715090