code: def _attach(
      attach_id: Optional[str] = None,
      run_id: Optional[str] = None,
      *,
      run: Optional["Run"] = None,
  ) -> Union[Run, RunDisabled, None]:
      """Attach to a run currently executing in another process/thread.
  
      Arguments:
          attach_id: (str, optional) The id of the run or an attach identifier
              that maps to a run.
          run_id: (str, optional) The id of the run to attach to.
          run: (Run, optional) The run instance to attach
      """
      attach_id = attach_id or run_id
      if not ((attach_id is None) ^ (run is None)):
          raise UsageError(
              "Either (`attach_id` or `run_id`) or `run` must be specified"
          )
  
      attach_id = attach_id or (run._attach_id if run else None)
  
      if attach_id is None:
          raise UsageError(
              "Either `attach_id` or `run_id` must be specified or `run` must have `_attach_id`"
          )
      wandb._assert_is_user_process()
  
      _wl = wandb_setup._setup()
      assert _wl
  
      _set_logger(_wl._get_logger())
      if logger is None:
          raise UsageError("logger is not initialized")
  
      manager = _wl._get_manager()
      response = (
          manager._inform_attach(attach_id=attach_id)
          if manager
          else None
      )
      if response is None:
          raise UsageError(f"Unable to attach to run {attach_id}")
  
      settings: Settings = copy.copy(_wl._settings)
  
      settings.update(
          {
              "run_id": attach_id,
              "_start_time": response._start_time.value,
              "_start_datetime": response._start_datetime.value,
              "_offline": response._offline.value,
          },
          source=Source.INIT,
      )
  
      # TODO: consolidate this codepath with wandb.init()
      mailbox = Mailbox()
      backend = Backend(
          settings=settings, manager=manager, mailbox=mailbox
      )
      backend.ensure_launched()
      logger.info("attach backend started and connected")
  
      if run is None:
          run = Run(settings=settings)
      else:
          run._init(settings=settings)
      run._set_library(_wl)
      run._set_backend(backend)
      backend._hack_set_run(run)
      assert backend.interface
  
      mailbox.enable_keepalive()
  
      attach_handle = backend.interface.deliver_attach(attach_id)
      # TODO: add progress to let user know we are doing something
      attach_result = attach_handle.wait(timeout=30)
      if not attach_result:
          attach_handle.abandon()
          raise UsageError("Timeout attaching to run")
      attach_response = attach_result.response.attach_response
      if attach_response.error and attach_response.error.message:
          raise UsageError(
              f"Failed to attach to run: {attach_response.error.message}"
          )
  
      run._set_run_obj(attach_response.run)
      run._on_attach()
      return run
  
imports: import copy
  import json
  import logging
  import os
  import platform
  import sys
  import tempfile
  import traceback
  from typing import TYPE_CHECKING, Any, Dict, List, Optional, Sequence, Union
  import wandb
  import wandb.env
  from wandb import trigger
  from wandb.errors import CommError, Error, UsageError
  from wandb.errors.util import ProtobufErrorHandler
  from wandb.integration import sagemaker
  from wandb.integration.magic import magic_install
  from wandb.sdk.lib import runid
  from wandb.sdk.lib.paths import StrPath
  from wandb.util import _is_artifact_representation
  from .None import wandb_login, wandb_setup
  from .backend.backend import Backend
  from .lib import RunDisabled, SummaryDisabled, filesystem, ipython, module, reporting, telemetry
  from .lib.deprecate import Deprecated, deprecate
  from .lib.mailbox import Mailbox, MailboxProgress
  from .lib.printer import Printer, get_printer
  from .lib.wburls import wburls
  from .wandb_helper import parse_config
  from .wandb_run import Run, TeardownHook, TeardownStage
  from .wandb_settings import Settings, Source
label_desc: Use image node_id 6 for calling a global function with example usage: _attach(attach_id, run_id) and returns: run