Skip to content

Commit

Permalink
Use polling for job status instead of websockets
Browse files Browse the repository at this point in the history
  • Loading branch information
kt474 committed Jun 27, 2024
1 parent 10b21f4 commit b970723
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 20 deletions.
11 changes: 1 addition & 10 deletions qiskit_ibm_runtime/runtime_job.py
Original file line number Diff line number Diff line change
Expand Up @@ -319,10 +319,7 @@ def wait_for_final_state( # pylint: disable=arguments-differ
self,
timeout: Optional[float] = None,
) -> None:
"""Use the websocket server to wait for the final the state of a job.
The server will remain open if the job is still running and the connection will
be terminated once the job completes. Then update and return the status of the job.
"""Poll for the job status from the API until the status is in a final state.
Args:
timeout: Seconds to wait for the job. If ``None``, wait indefinitely.
Expand All @@ -332,12 +329,6 @@ def wait_for_final_state( # pylint: disable=arguments-differ
"""
try:
start_time = time.time()
if self._status not in self.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)
# 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 self.JOB_FINAL_STATES:
elapsed_time = time.time() - start_time
Expand Down
11 changes: 1 addition & 10 deletions qiskit_ibm_runtime/runtime_job_v2.py
Original file line number Diff line number Diff line change
Expand Up @@ -236,10 +236,7 @@ def wait_for_final_state( # pylint: disable=arguments-differ
self,
timeout: Optional[float] = None,
) -> None:
"""Use the websocket server to wait for the final the state of a job.
The server will remain open if the job is still running and the connection will
be terminated once the job completes. Then update and return the status of the job.
"""Poll for the job status from the API until the status is in a final state.
Args:
timeout: Seconds to wait for the job. If ``None``, wait indefinitely.
Expand All @@ -249,12 +246,6 @@ def wait_for_final_state( # pylint: disable=arguments-differ
"""
try:
start_time = time.time()
if self._status not in self.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)
# 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 self.JOB_FINAL_STATES:
elapsed_time = time.time() - start_time
Expand Down

0 comments on commit b970723

Please sign in to comment.