code: def query_cpu() -> int:
      """
      Queries alloted CPUs.
      Source: https://bugs.python.org/issue36054.
      :return: Alloted CPUs.
      """
  
      cpu_quota = -1
  
      if os.path.isfile("/sys/fs/cgroup/cpu/cpu.cfs_quota_us"):
          # Not useful for AWS Batch based jobs as result is -1, but works on local linux systems
          cpu_quota = int(
              open("/sys/fs/cgroup/cpu/cpu.cfs_quota_us")
              .read()
              .rstrip()
          )
      if cpu_quota != -1 and os.path.isfile(
          "/sys/fs/cgroup/cpu/cpu.cfs_period_us"
      ):
          cpu_period = int(
              open("/sys/fs/cgroup/cpu/cpu.cfs_period_us")
              .read()
              .rstrip()
          )
          # Divide quota by period and you should get num of allotted CPU to the container, rounded down if fractional.
          avail_cpu = int(cpu_quota / cpu_period)
      elif os.path.isfile("/sys/fs/cgroup/cpuset/cpuset.cpus"):
          # Has potentially repeating, comma-separated groups of CPU_idx-CPU_idx or just CPU_idx.
          avail_cpu = 0
          for cpu_group in (
              open("/sys/fs/cgroup/cpuset/cpuset.cpus")
              .read()
              .rstrip()
              .split(",")
          ):
              cpu_range = cpu_group.split("-")
              avail_cpu += (
                  int(
                      cpu_range[1]
                      if len(cpu_range) == 2
                      else cpu_range[0]
                  )
                  - int(cpu_range[0])
                  + 1
              )
      else:
          avail_cpu = os.cpu_count()
  
      return avail_cpu
  
file_path: maze/maze/utils/process.py
imports: import multiprocessing
  from typing import Optional, Any
  from maze.utils.log_stats_utils import clear_global_state
  import os
  import re
  import subprocess
label_desc: Use image node_id 1 for calling a global function with example usage: query_cpu() and returns: avail_cpu