Checking for Timeout Error

for _ in range(60):
            try:
                main_window.TaskApp.child_window(title="Task 1", control_type="Window").wait(timeout=5 ,retry_interval=1, wait_for="visible")
                break
            except TimeoutError: 
                print('Timeout error')
                continue

Hi there, I’m trying to intercept this timeout error, but without success.

wait_until_passes raise err pywinauto.timings.TimeoutError

Hi @Hub, how are you?

Apparently, pywinauto is throwing TimeOut but not being caught by the exception.

One option is to import TimeOutError from the pywinauto module to ensure the except block catches an exception correctly, like this:

import pywinauto.timings

for _ in range(60):
    try:
        ...
    except pywinauto.timings.TimeoutError:
        print('Timeout error')
        continue

Also, evaluate the need to break it inside the try, check if it can’t be disturbing in this case, or if it might not be more interesting to put it outside the try, in else one for example.

1 Like