10 examples of 'python wait until' in Python

Every line of 'python wait until' code snippets is scanned for vulnerabilities by our powerful machine learning engine that combs millions of open source libraries, ensuring your Python code is secure.

All examples are scanned by Snyk Code

By copying the Snyk Code Snippets you agree to
34def wait_for(condition, timeout=10):
35 start = time.time()
36 while not condition() and time.time() - start < timeout:
37 time.sleep(0.1)
38
39 return condition()
1716def wait_for_condition(self,script,timeout):
1717 """
1718 Runs the specified JavaScript snippet repeatedly until it evaluates to "true".
1719 The snippet may have multiple lines, but only the result of the last line
1720 will be considered.
1721
1722
1723 Note that, by default, the snippet will be run in the runner's test window, not in the window
1724 of your application. To get the window of your application, you can use
1725 the JavaScript snippet ``selenium.browserbot.getCurrentWindow()``, and then
1726 run your JavaScript in there
1727
1728
1729 'script' is the JavaScript snippet to run
1730 'timeout' is a timeout in milliseconds, after which this command will return with an error
1731 """
1732 self.do_command("waitForCondition", [script,timeout,])
201def wait_until(predicate, *, attempts=float('inf'), timeout=float('inf'), lock=None):
202 if attempts == float('inf') and timeout == float('inf'):
203 timeout = 60
204 attempt = 0
205 time_end = time.time() + timeout
206
207 while attempt < attempts and time.time() < time_end:
208 if lock:
209 with lock:
210 if predicate():
211 return
212 else:
213 if predicate():
214 return
215 attempt += 1
216 time.sleep(0.05)
217
218 # Print the cause of the timeout
219 predicate_source = inspect.getsourcelines(predicate)
220 logger.error("wait_until() failed. Predicate: {}".format(predicate_source))
221 if attempt >= attempts:
222 raise AssertionError("Predicate {} not true after {} attempts".format(predicate_source, attempts))
223 elif time.time() >= time_end:
224 raise AssertionError("Predicate {} not true after {} seconds".format(predicate_source, timeout))
225 raise RuntimeError('Unreachable')
122def wait_for(cond: typing.Callable[[], bool], timeout: float= 5):
123 start_time = time.time()
124 while True:
125 if cond():
126 return
127
128 if time.time() - start_time > timeout:
129 raise AssertionError('Timeout expired')
130
131 Gtk.main_iteration_do(False)
71def wait(interval=0.1):
72 """ Convenience function to adjust sleep interval for all tests. """
73 time.sleep(interval)
71def poll_until(
72 function: Callable[[], Optional[T]],
73 timeout: float,
74 interval: float = 0.2,
75 timeout_ex: Optional[Exception] = None,
76) -> T:
77 """
78 Call the specified function repeatedly until it returns non-None.
79 Returns the function result.
80
81 Sleep 'interval' seconds between calls. If 'timeout' seconds passes
82 before the function returns a non-None result, raise an exception.
83 If a 'timeout_ex' argument is supplied, that exception object is
84 raised, otherwise a TimeoutError is raised.
85 """
86 end_time = time.time() + timeout
87 while True:
88 result = function()
89 if result is not None:
90 return result
91
92 if time.time() >= end_time:
93 if timeout_ex is not None:
94 raise timeout_ex
95 raise TimeoutError(
96 "timed out waiting on function {}".format(function.__name__)
97 )
98
99 time.sleep(interval)
37def wait(*args):
38 input(colors.BLUE + fmt(args) + colors.END)
30def wait(self, timeout=0):
31 return self._event.wait(timeout)
52def wait_for(self, interval=None, timeout=None):
53 """
54 Get a ElementWaitFor instance.
55
56 :param interval: the wait interval (in milliseconds). If None, use element's wait interval.
57 :param timeout: the wait timeout (in milliseconds). If None, use element's wait timeout.
58 """
59 _interval = self.get_wait_interval() if interval is None else interval
60 _timeout = self.get_wait_timeout() if timeout is None else timeout
61 return ElementWaitFor(self, _interval, _timeout)
230def wait(self, time_to_wait):
231 # wait for a specified duration of time, in seconds. This command is blocking.
232 if isinstance(self.device, VrepInterface):
233 # timesteps to wait, rounded down to the nearest integer
234 self.device.wait(int(time_to_wait / self.device.dt))
235 if isinstance(self.device, DxlInterface):
236 time.sleep(time_to_wait)

Related snippets