code: def has_cuda_context():
      """Check whether the current process already has a CUDA context created.
  
      Returns
      -------
      out : CudaContext
          Object containing information as to whether the current process has a CUDA
          context created, and in the positive case containing also information about
          the device the context belongs to.
      """
      init_once()
      if is_initialized():
          for index in range(device_get_count()):
              handle = pynvml.nvmlDeviceGetHandleByIndex(index)
              try:
                  (
                      mig_current_mode,
                      mig_pending_mode,
                  ) = pynvml.nvmlDeviceGetMigMode(handle)
              except pynvml.NVMLError_NotSupported:
                  mig_current_mode = pynvml.NVML_DEVICE_MIG_DISABLE
              if mig_current_mode == pynvml.NVML_DEVICE_MIG_ENABLE:
                  for mig_index in range(
                      pynvml.nvmlDeviceGetMaxMigDeviceCount(handle)
                  ):
                      try:
                          mig_handle = pynvml.nvmlDeviceGetMigDeviceHandleByIndex(
                              handle, mig_index
                          )
                      except pynvml.NVMLError_NotFound:
                          # No MIG device with that index
                          continue
                      if _running_process_matches(mig_handle):
                          uuid = pynvml.nvmlDeviceGetUUID(mig_handle)
                          return CudaContext(
                              has_context=True,
                              device_info=CudaDeviceInfo(
                                  uuid=uuid,
                                  device_index=index,
                                  mig_index=mig_index,
                              ),
                          )
              else:
                  if _running_process_matches(handle):
                      uuid = pynvml.nvmlDeviceGetUUID(handle)
                      return CudaContext(
                          has_context=True,
                          device_info=CudaDeviceInfo(
                              uuid=uuid, device_index=index
                          ),
                      )
      return CudaContext(has_context=False)
  
imports: from __future__ import annotations
  import os
  from enum import IntEnum, auto
  from platform import uname
  from typing import NamedTuple
  from packaging.version import parse
  import dask
label_desc: Use image node_id 7 for calling a global function with example usage: has_cuda_context() and returns: CudaContext, CudaContext, CudaContext