{"record":{"id":"255ed8e2c2b27e4f","repo":"apache/beam","slug":"timeout-waiting-for-asynchronous-computation-completion","errorCode":null,"errorMessage":"Timeout waiting for asynchronous computation completion.","messagePattern":"Timeout waiting for asynchronous computation completion\\.","errorType":"exception","errorClass":"TimeoutError","httpStatus":null,"severity":"error","filePath":"sdks/python/apache_beam/runners/interactive/recording_manager.py","lineNumber":158,"sourceCode":"    self._pipeline_result = pipeline_result\n    if self._cancel_requested:\n      self.cancel()\n\n  def result(self, timeout=None):\n    return self._future.result(timeout=timeout)\n\n  def done(self):\n    return self._future.done()\n\n  def exception(self, timeout=None):\n    try:\n      return self._future.exception(timeout=timeout)\n    except TimeoutError:\n      return None\n\n  def wait_for_completion(self, timeout=None):\n    if not self._completed_event.wait(timeout=timeout):\n      raise TimeoutError(\n          'Timeout waiting for asynchronous computation completion.')\n    if self._future.cancelled():\n      raise RuntimeError('Asynchronous computation was cancelled.')\n    exc = self.exception()\n    if exc:\n      raise exc\n\n  def _on_done(self, future: Future):\n    try:\n      if future.cancelled():\n        self.update_display('Computation Cancelled.', 1.0)\n        return\n\n      exc = future.exception()\n      if exc:\n        self.update_display(f'Error: {exc}', 1.0)\n        _LOGGER.error('Asynchronous computation failed: %s', exc, exc_info=exc)\n      else:","sourceCodeStart":140,"sourceCodeEnd":176,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/python/apache_beam/runners/interactive/recording_manager.py#L140-L176","documentation":"Recording.wait_for_completion blocks on a threading.Event that the background recording thread sets when done. If the event is not set within the optional timeout, the method raises TimeoutError to signal that the asynchronous pipeline recording did not finish in time.","triggerScenarios":"Calling ib.collect / recording.watch with a recording whose underlying Beam pipeline takes longer than the supplied timeout; passing a small timeout to Recording.wait_for_completion while the pipeline is still running.","commonSituations":"Interactive Beam notebooks with long-running pipelines (large inputs, slow runners like Dataflow), or code that polls a recording with a tight timeout instead of streaming incrementally.","solutions":["Increase or omit the timeout passed to wait_for_completion / the recording's max duration so slow pipelines can finish","Stream results incrementally with recording.stream() instead of waiting for the full computation","Check pipeline health in the runner (Dataflow job status, logs) to see why the computation is slow","Poll wait_for_completion with progressive timeouts in a loop rather than one short timeout"],"exampleFix":"// before\nrecording.wait_for_completion(timeout=10)\n// after\nrecording.wait_for_completion(timeout=None)  # wait as long as needed\n# or poll:\nwhile not recording.computed:\n    time.sleep(5)\nrecording.wait_for_completion()","handlingStrategy":"try-catch","validationCode":"if recording.computed:\n    recording.wait_for_completion()\nelif recording.max_duration and est_runtime > recording.max_duration:\n    raise RuntimeError('recording will exceed max_duration; increase it')","typeGuard":"def is_ready(rec):\n    return rec.computed or rec._completed_event.is_set()","tryCatchPattern":"try:\n    recording.wait_for_completion(timeout=60)\nexcept TimeoutError:\n    # pipeline still running; poll again or stream incrementally\n    pass","preventionTips":["Pass a generous timeout or None when pipelines are long-running","Use recording.stream() for incremental results instead of full completion waits","Monitor runner logs for pipeline progress before waiting","Set max_duration appropriately for the expected data volume"],"tags":["timeout","async","interactive-beam"],"backgroundTag":"request-timeout","analyzedSha":"12126d8942aaf848030c478b4c6a28c6af861c66","analyzedAt":"2026-09-13T01:50:10.254Z","contentChangedAt":"2026-09-13T01:50:10.254Z","schemaVersion":2},"datasetVersion":"2026-09-20T03:17:13.778Z"}