class_docstr: Run the optimization process given the current executor
class_docstr_tok: ["Run","the","optimization","process","given","the","current","executor"]
docstr: Gather the results from each worker asynchronously
docstr_tok: ["Gather","the","results","from","each","worker","asynchronously"]
code: def gather(self):
      """Gather the results from each worker asynchronously"""
      results = self.client.executor.async_get(
          self.futures, timeout=self.gather_timeout
      )
  
      to_be_raised = None
      if results:
          log.debug(f"Gathered new results {len(results)}")
      # register the results
      # NOTE: For Ptera instrumentation
      trials = 0  # pylint:disable=unused-variable
      for result in results:
          trial = self.pending_trials.pop(result.future, None)
  
          if trial is None:
              log.warning(
                  f"Future does not have a matching trial, {result}"
              )
  
          if isinstance(result, AsyncResult):
              try:
                  # NB: observe release the trial already
                  self.client.observe(trial, result.value)
                  self.trials += 1
                  # NOTE: For Ptera instrumentation
                  trials = self.trials  # pylint:disable=unused-variable
              except InvalidResult as exception:
                  # stop the optimization process if we received `InvalidResult`
                  # as all the trials are assumed to be returning those
                  to_be_raised = exception
                  self.client.release(trial, status="broken")
  
          if isinstance(result, AsyncException):
              if (
                  isinstance(result.exception, ExecutionError)
                  and result.exception.return_code
                  == self.interrupt_signal_code
              ):
                  to_be_raised = KeyboardInterrupt()
                  self.client.release(trial, status="interrupted")
                  continue
  
              # Regular exception, might be caused by the chosen hyperparameters
              # themselves rather than the code in particular (like Out of Memory error
              # for big batch sizes)
              exception = result.exception
              self.worker_broken_trials += 1
              self.client.release(trial, status="broken")
  
              if self.on_error is None or self.on_error(
                  self, trial, exception, self.worker_broken_trials
              ):
                  log.error(result.traceback)
  
              else:
                  log.error(str(exception))
                  log.debug(result.traceback)
  
      # if we receive too many broken trials, it might indicate the user script
      # is broken, stop the experiment and let the user investigate
      if self.is_broken:
          to_be_raised = BrokenExperiment(
              "Worker has reached broken trials threshold"
          )
  
      if to_be_raised is not None:
          log.debug("Runner was interrupted")
          self._release_all()
          raise to_be_raised
  
      return len(results)
  
imports: from __future__ import annotations
  import logging
  import os
  import shutil
  import signal
  import time
  import typing
  import warnings
  from contextlib import contextmanager
  from dataclasses import dataclass
  from typing import Callable
  import orion.core
  from orion.core.utils import backward
  from orion.core.utils.exceptions import BrokenExperiment, CompletedExperiment, InvalidResult, LazyWorkers, ReservationRaceCondition, WaitingForTrials
  from orion.core.utils.flatten import flatten, unflatten
  from orion.core.worker.consumer import ExecutionError
  from orion.core.worker.trial import AlreadyReleased
  from orion.executor.base import AsyncException, AsyncResult
  from orion.storage.base import LockAcquisitionTimeout
label_desc: Use image node_id 12 for calling the Runner obj's underlying member method code with example usage: obj.gather() and returns: len