diff --git a/docs/release_notes.rst b/docs/release_notes.rst index e89f6c9711..ec77acc34c 100644 --- a/docs/release_notes.rst +++ b/docs/release_notes.rst @@ -1,2 +1 @@ .. release-notes:: Release Notes - :version: 0.4.0, 0.3.0, 0.2.0, 0.1.0, 0.1.0rc2, 0.1.0rc1 \ No newline at end of file diff --git a/qiskit_ibm_runtime/runtime_job.py b/qiskit_ibm_runtime/runtime_job.py index c2e5205a92..3743bed7c0 100644 --- a/qiskit_ibm_runtime/runtime_job.py +++ b/qiskit_ibm_runtime/runtime_job.py @@ -13,6 +13,7 @@ """Qiskit runtime job.""" from typing import Any, Optional, Callable, Dict, Type +import time import logging from concurrent import futures import traceback @@ -232,13 +233,24 @@ def wait_for_final_state(self, timeout: Optional[float] = None) -> None: RuntimeJobTimeoutError: If the job does not complete within given timeout. """ try: + start_time = time.time() if self._status not in JOB_FINAL_STATES and not self._is_streaming(): self._ws_client_future = self._executor.submit( self._start_websocket_client ) if self._is_streaming(): self._ws_client_future.result(timeout) - self.status() + # poll for status after stream has closed until status is final + # because status doesn't become final as soon as stream closes + status = self.status() + while status not in JOB_FINAL_STATES: + elapsed_time = time.time() - start_time + if timeout is not None and elapsed_time >= timeout: + raise RuntimeJobTimeoutError( + f"Timed out waiting for job to complete after {timeout} secs." + ) + time.sleep(3) + status = self.status() except futures.TimeoutError: raise RuntimeJobTimeoutError( f"Timed out waiting for job to complete after {timeout} secs."