Waits for the given file to be processed, default timeout is 30 mins.
(
self,
id: str,
*,
poll_interval: float = 5.0,
max_wait_seconds: float = 30 * 60,
)
| 364 | ) |
| 365 | |
| 366 | def wait_for_processing( |
| 367 | self, |
| 368 | id: str, |
| 369 | *, |
| 370 | poll_interval: float = 5.0, |
| 371 | max_wait_seconds: float = 30 * 60, |
| 372 | ) -> FileObject: |
| 373 | class="st">""class="st">"Waits for the given file to be processed, default timeout is 30 mins."class="st">"" |
| 374 | TERMINAL_STATES = {class="st">"processed", class="st">"error", class="st">"deleted"} |
| 375 | |
| 376 | start = time.time() |
| 377 | file = self.retrieve(id) |
| 378 | while file.status not in TERMINAL_STATES: |
| 379 | self._sleep(poll_interval) |
| 380 | |
| 381 | file = self.retrieve(id) |
| 382 | if time.time() - start > max_wait_seconds: |
| 383 | raise RuntimeError( |
| 384 | fclass="st">"Giving up on waiting for file {id} to finish processing after {max_wait_seconds} seconds." |
| 385 | ) |
| 386 | |
| 387 | return file |
| 388 | |
| 389 | |
| 390 | class AsyncFiles(AsyncAPIResource): |