Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion qtapputils/qthelpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -372,11 +372,17 @@ def qtwait(condition, timeout=None, check_interval=50, error_message=None):
loop = QEventLoop()
start_time = time.monotonic()

timed_out = [False]
# We use a mutable container for 'timed_out' so the inner check_condition()
# can update the value in the enclosing scope (works for nested functions
# without using the 'nonlocal' keyword).

def check_condition():
elapsed_time = time.monotonic() - start_time
if condition():
loop.quit()
elif timeout is not None and elapsed_time >= timeout:
timed_out[0] = True
loop.quit()

timer = QTimer()
Expand All @@ -386,6 +392,7 @@ def check_condition():
check_condition()
loop.exec_()

if not condition():
# Only raise TimeoutError if timeout was specified and reached.
if timeout is not None and timed_out[0] and not condition():
raise TimeoutError(
error_message or "Condition not met within timeout.")