@@ -197,30 +197,40 @@ def _refresh(self, indices: Sequence[int], *, wait: bool = False) -> Iterator[li
197197 groups .setdefault (id (handle ), []).append (index )
198198 for group in groups .values ():
199199 pending = [i for i in group if self ._entries [i ].attempts [- 1 ].status not in _TERMINAL ]
200- if pending :
201- handle = self ._entries [pending [0 ]].attempts [- 1 ].handle
202- assert handle is not None
203- stage = "wait" if wait else "status"
204- try : # ruff:ignore[too-many-statements-in-try-clause] Keep shared query failures on every affected entry.
205- if wait and not handle .wait ():
206- msg = "Timed out waiting for the QDMI job."
207- raise TimeoutError (msg ) # ruff:ignore[raise-within-try] Record timeouts with other wait failures.
208- stage = "status"
209- aggregate = handle .check ()
210- # Resolve individual outcomes before attributing an aggregate failure.
211- for index in pending :
212- attempt = self ._entries [index ].attempts [- 1 ]
200+ if not pending :
201+ yield group
202+ continue
203+ handle = self ._entries [pending [0 ]].attempts [- 1 ].handle
204+ assert handle is not None
205+ stage = "wait" if wait else "status"
206+ try :
207+ if wait and not handle .wait ():
208+ msg = "Timed out waiting for the QDMI job."
209+ raise TimeoutError (msg ) # ruff:ignore[raise-within-try] Record timeouts with other wait failures.
210+ stage = "status"
211+ aggregate = handle .check ()
212+ except BaseException as exc :
213+ for index in pending :
214+ attempt = self ._entries [index ].attempts [- 1 ]
215+ self ._set_attempt (index , replace (attempt , status = None ))
216+ self .record_failure (index , stage , exc )
217+ if not isinstance (exc , Exception ):
218+ raise
219+ else :
220+ # Resolve individual outcomes before attributing an aggregate failure.
221+ for index in pending :
222+ attempt = self ._entries [index ].attempts [- 1 ]
223+ try :
213224 status = aggregate
214225 if aggregate in {Job .Status .FAILED , Job .Status .CANCELED }:
215226 status = handle .get_program_status (attempt .program_index ) or aggregate
216- self ._set_attempt (index , replace (attempt , status = status ))
217- except BaseException as exc :
218- for index in pending :
219- attempt = self ._entries [index ].attempts [- 1 ]
227+ except BaseException as exc :
220228 self ._set_attempt (index , replace (attempt , status = None ))
221- self .record_failure (index , stage , exc )
222- if not isinstance (exc , Exception ):
223- raise
229+ self .record_failure (index , "status" , exc )
230+ if not isinstance (exc , Exception ):
231+ raise
232+ else :
233+ self ._set_attempt (index , replace (attempt , status = status ))
224234 yield group
225235
226236 def statuses (self ) -> tuple [Job .Status | None , ...]:
0 commit comments