Skip to content

Commit

Permalink
Use polling for job status instead of websockets (#1778)
Browse files Browse the repository at this point in the history
  • Loading branch information
kt474 authored Jul 1, 2024
1 parent b6865b4 commit c607150
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 @@ -320,10 +320,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 @@ -333,12 +330,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 @@ -237,10 +237,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 @@ -250,12 +247,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 c607150

Please sign in to comment.