Continually polls the status of the document translation associated with the given handle, sleeping in between requests, and returns the final status when the translation completes (whether successful or not). :param handle: DocumentHandle to the document tra
(
self,
handle: DocumentHandle,
timeout_s: Optional[int] = None,
)
| 880 | ) |
| 881 | |
| 882 | def translate_document_wait_until_done( |
| 883 | self, |
| 884 | handle: DocumentHandle, |
| 885 | timeout_s: Optional[int] = None, |
| 886 | ) -> DocumentStatus: |
| 887 | """ |
| 888 | Continually polls the status of the document translation associated |
| 889 | with the given handle, sleeping in between requests, and returns the |
| 890 | final status when the translation completes (whether successful or |
| 891 | not). |
| 892 | :param handle: DocumentHandle to the document translation to wait on. |
| 893 | :param timeout_s: (beta) (Optional) Maximum time to wait before |
| 894 | the call raises an error. Note that this is not accurate to the |
| 895 | second, but only polls every 5 seconds. |
| 896 | :return: DocumentStatus containing the status when completed. |
| 897 | """ |
| 898 | status = self.translate_document_get_status(handle) |
| 899 | start_time_s = time.time() |
| 900 | while status.ok and not status.done: |
| 901 | if ( |
| 902 | timeout_s is not None |
| 903 | and time.time() - start_time_s > timeout_s |
| 904 | ): |
| 905 | raise DeepLException( |
| 906 | f"Manual timeout of {timeout_s}s exceeded for" |
| 907 | + " document translation", |
| 908 | should_retry=False, |
| 909 | ) |
| 910 | else: |
| 911 | secs = ( |
| 912 | 5.0 # seconds_remaining is currently unreliable, so just |
| 913 | ) |
| 914 | # poll equidistantly |
| 915 | util.log_info( |
| 916 | f"Rechecking document translation status " |
| 917 | f"after sleeping for {secs:.3f} seconds." |
| 918 | ) |
| 919 | time.sleep(secs) |
| 920 | status = self.translate_document_get_status(handle) |
| 921 | return status |
| 922 | |
| 923 | def translate_document_download( |
| 924 | self, |
no test coverage detected