code: def get_affinity_core_num():
      # When using proclist to bind cores,
      # `os.sched_getaffinity(0)` will return only the first bound core,
      # so we need to parse KMP_AFFINITY manually in this case
      KMP_AFFINITY = os.environ.get("KMP_AFFINITY", "")
      if "compact" in KMP_AFFINITY:
          affinity_core_num = None
      elif "proclist" in KMP_AFFINITY:
          try:
              start_pos = (
                  KMP_AFFINITY.find("[", KMP_AFFINITY.find("proclist"))
                  + 1
              )
              end_pos = KMP_AFFINITY.find("]", start_pos)
              proclist_str = KMP_AFFINITY[start_pos:end_pos].replace(
                  " ", ""
              )
              core_list = []
              for n in proclist_str.split(","):
                  if "-" not in n:
                      core_list.append(int(n))
                  else:
                      start, end = n.split("-")
                      core_list.extend(range(int(start), int(end) + 1))
              affinity_core_num = len(core_list)
          except Exception as _e:
              warnings.warn(
                  f"Failed to parse KMP_AFFINITY: '{KMP_AFFINITY}'."
              )
              affinity_core_num = None
      else:
          affinity_core_num = len(os.sched_getaffinity(0))
  
      return affinity_core_num
  
label_desc: Use image node_id 1 for calling a global function with example usage: get_affinity_core_num() and returns: affinity_core_num