code: def init(self) -> Union[Run, RunDisabled, None]:  # noqa: C901
      if logger is None:
          raise RuntimeError("Logger not initialized")
      logger.info("calling init triggers")
      trigger.call("on_init", **self.kwargs)  # type: ignore
  
      assert self.settings is not None
      assert self._wl is not None
      assert self._reporter is not None
  
      logger.info(
          f"wandb.init called with sweep_config: {self.sweep_config}\nconfig: {self.config}"
      )
  
      if self.settings._noop:
          return self._make_run_disabled()
      if self.settings.reinit or (
          self.settings._jupyter and self.settings.reinit is not False
      ):
          if len(self._wl._global_run_stack) > 0:
              if len(self._wl._global_run_stack) > 1:
                  wandb.termwarn(
                      "If you want to track multiple runs concurrently in wandb, "
                      "you should use multi-processing not threads"
                  )
  
              latest_run = self._wl._global_run_stack[-1]
  
              logger.info(
                  f"re-initializing run, found existing run on stack: {latest_run._run_id}"
              )
  
              jupyter = self.settings._jupyter
              if jupyter and not self.settings.silent:
                  ipython.display_html(
                      f"Finishing last run (ID:{latest_run._run_id}) before initializing another..."
                  )
  
              latest_run.finish()
  
              if jupyter and not self.settings.silent:
                  ipython.display_html(
                      f"Successfully finished last run (ID:{latest_run._run_id}). Initializing new run:<br/>"
                  )
      elif isinstance(wandb.run, Run):
          manager = self._wl._get_manager()
          # We shouldn't return a stale global run if we are in a new pid
          if not manager or os.getpid() == wandb.run._init_pid:
              logger.info(
                  "wandb.init() called when a run is still active"
              )
              with telemetry.context() as tel:
                  tel.feature.init_return_run = True
              return wandb.run
  
      logger.info("starting backend")
  
      manager = self._wl._get_manager()
      if manager:
          logger.info("setting up manager")
          manager._inform_init(
              settings=self.settings.to_proto(),
              run_id=self.settings.run_id,
          )
  
      mailbox = Mailbox()
      backend = Backend(
          settings=self.settings, manager=manager, mailbox=mailbox
      )
      backend.ensure_launched()
      logger.info("backend started and connected")
      # Make sure we are logged in
      # wandb_login._login(_backend=backend, _settings=self.settings)
  
      # resuming needs access to the server, check server_status()?
      run = Run(
          config=self.config,
          settings=self.settings,
          sweep_config=self.sweep_config,
          launch_config=self.launch_config,
      )
  
      # Populate initial telemetry
      with telemetry.context(
          run=run, obj=self._init_telemetry_obj
      ) as tel:
          tel.cli_version = wandb.__version__
          tel.python_version = platform.python_version()
          tel.platform = (
              f"{platform.system()}-{platform.machine()}".lower()
          )
          hf_version = _huggingface_version()
          if hf_version:
              tel.huggingface_version = hf_version
          if self.settings._jupyter:
              tel.env.jupyter = True
          if self.settings._ipython:
              tel.env.ipython = True
          if self.settings._colab:
              tel.env.colab = True
          if self.settings._kaggle:
              tel.env.kaggle = True
          if self.settings._windows:
              tel.env.windows = True
  
          if self.settings.launch:
              tel.feature.launch = True
  
          if self.settings._async_upload_concurrency_limit:
              tel.feature.async_uploads = True
  
          for module_name in telemetry.list_telemetry_imports(
              only_imported=True
          ):
              setattr(tel.imports_init, module_name, True)
  
          # probe the active start method
          active_start_method: Optional[str] = None
          if self.settings.start_method == "thread":
              active_start_method = self.settings.start_method
          else:
              active_start_method = getattr(
                  backend._multiprocessing,
                  "get_start_method",
                  lambda: None,
              )()
  
          if active_start_method == "spawn":
              tel.env.start_spawn = True
          elif active_start_method == "fork":
              tel.env.start_fork = True
          elif active_start_method == "forkserver":
              tel.env.start_forkserver = True
          elif active_start_method == "thread":
              tel.env.start_thread = True
  
          if os.environ.get("PEX"):
              tel.env.pex = True
  
          if self.settings._aws_lambda:
              tel.env.aws_lambda = True
  
          if os.environ.get(wandb.env._DISABLE_SERVICE):
              tel.feature.service_disabled = True
  
          if manager:
              tel.feature.service = True
          if self.settings._flow_control_disabled:
              tel.feature.flow_control_disabled = True
          if self.settings._flow_control_custom:
              tel.feature.flow_control_custom = True
          if self.settings._require_core:
              tel.feature.core = True
  
          tel.env.maybe_mp = _maybe_mp_process(backend)
  
      if not self.settings.label_disable:
          if self.notebook:
              run._label_probe_notebook(self.notebook)
          else:
              run._label_probe_main()
  
      for (
          deprecated_feature,
          msg,
      ) in self.deprecated_features_used.items():
          warning_message = (
              f"`{deprecated_feature}` is deprecated. {msg}"
          )
          deprecate(
              field_name=getattr(
                  Deprecated, "init__" + deprecated_feature
              ),
              warning_message=warning_message,
              run=run,
          )
  
      logger.info("updated telemetry")
  
      run._set_library(self._wl)
      run._set_backend(backend)
      run._set_reporter(self._reporter)
      run._set_teardown_hooks(self._teardown_hooks)
  
      backend._hack_set_run(run)
      assert backend.interface
      mailbox.enable_keepalive()
      backend.interface.publish_header()
  
      # Using GitRepo() blocks & can be slow, depending on user's current git setup.
      # We don't want to block run initialization/start request, so populate run's git
      # info beforehand.
      if not self.settings.disable_git:
          run._populate_git_info()
  
      run_result: Optional[pb.RunUpdateResult] = None
  
      if self.settings._offline:
          with telemetry.context(run=run) as tel:
              tel.feature.offline = True
  
          if self.settings.resume:
              wandb.termwarn(
                  "`resume` will be ignored since W&B syncing is set to `offline`. "
                  f"Starting a new run with run id {run.id}."
              )
      error: Optional[wandb.errors.Error] = None
  
      timeout = self.settings.init_timeout
  
      logger.info(
          f"communicating run to backend with {timeout} second timeout"
      )
  
      run_init_handle = backend.interface.deliver_run(run)
      result = run_init_handle.wait(
          timeout=timeout,
          on_progress=self._on_progress_init,
          cancel=True,
      )
      if result:
          run_result = result.run_result
  
      if run_result is None:
          error_message = (
              f"Run initialization has timed out after {timeout} sec. "
              f"\nPlease refer to the documentation for additional information: {wburls.get('doc_start_err')}"
          )
          # We're not certain whether the error we encountered is due to an issue
          # with the server (a "CommError") or if it's a problem within the SDK (an "Error").
          # This means that the error could be a result of the server being unresponsive,
          # or it could be because we were unable to communicate with the wandb service.
          error = CommError(error_message)
          run_init_handle._cancel()
      elif run_result.HasField("error"):
          error = ProtobufErrorHandler.to_exception(run_result.error)
  
      if error is not None:
          logger.error(f"encountered error: {error}")
          if not manager:
              # Shutdown the backend and get rid of the logger
              # we don't need to do console cleanup at this point
              backend.cleanup()
              self.teardown()
          raise error
  
      assert run_result is not None  # for mypy
  
      if not run_result.HasField("run"):
          raise Error(
              "It appears that something have gone wrong during the program execution as an unexpected missing field was encountered. "
              "(run_result is missing the 'run' field)"
          )
  
      if run_result.run.resumed:
          logger.info("run resumed")
          with telemetry.context(run=run) as tel:
              tel.feature.resumed = run_result.run.resumed
  
      run._set_run_obj(run_result.run)
  
      run._on_init()
  
      logger.info("starting run threads in backend")
      # initiate run (stats and metadata probing)
  
      if manager:
          manager._inform_start(
              settings=self.settings.to_proto(),
              run_id=self.settings.run_id,
          )
  
      assert backend.interface
      assert run._run_obj
  
      run_start_handle = backend.interface.deliver_run_start(
          run._run_obj
      )
      # TODO: add progress to let user know we are doing something
      run_start_result = run_start_handle.wait(timeout=30)
      if run_start_result is None:
          run_start_handle.abandon()
  
      assert self._wl is not None
      self._wl._global_run_stack.append(run)
      self.run = run
  
      run._handle_launch_artifact_overrides()
      if (
          self.settings.launch
          and self.settings.launch_config_path
          and os.path.exists(self.settings.launch_config_path)
      ):
          run._save(self.settings.launch_config_path)
      # put artifacts in run config here
      # since doing so earlier will cause an error
      # as the run is not upserted
      for k, v in self.init_artifact_config.items():
          run.config.update({k: v}, allow_val_change=True)
      job_artifact = run._launch_artifact_mapping.get(
          wandb.util.LAUNCH_JOB_ARTIFACT_SLOT_NAME
      )
      if job_artifact:
          run.use_artifact(job_artifact)
  
      self.backend = backend
      assert self._reporter
      self._reporter.set_context(run=run)
      run._on_start()
      logger.info("run started, returning control to user process")
      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 15 for calling the _WandbInit obj's underlying member method code with example usage: obj.init() and returns: run, self, wandb