Browse Source

wait_for_engine_window: implement timeout

Fabian Peter Hammerle 7 years ago
parent
commit
84c17bab3d
1 changed files with 4 additions and 3 deletions
  1. 4 3
      tooncher/__init__.py

+ 4 - 3
tooncher/__init__.py

@@ -169,13 +169,14 @@ def x_grab_key(grab_window, keycode, modifiers=None):
     )
 
 
-def wait_for_engine_window(xdisplay, engine_process):
-    while engine_process.poll() is None:  # TODO add timeout
+def wait_for_engine_window(xdisplay, engine_process, timeout_seconds=20, search_interval_seconds=2):
+    start_epoch = time.time()
+    while engine_process.poll() is None and (time.time() - start_epoch) <= timeout_seconds:
         windows = x_find_window_by_pid(xdisplay, engine_process.pid)
         assert len(windows) <= 1
         if len(windows) == 1:
             return windows[0]
-        time.sleep(2)
+        time.sleep(search_interval_seconds)
     return None