Wait until a condition evaluates to True. predicate should be a callable which result will be interpreted as a boolean value. A timeout may be provided giving the maximum time to wait.
(self, predicate, timeout=None)
| 376 | pass |
| 377 | |
| 378 | def wait_for(self, predicate, timeout=None): |
| 379 | """Wait until a condition evaluates to True. |
| 380 | |
| 381 | predicate should be a callable which result will be interpreted as a |
| 382 | boolean value. A timeout may be provided giving the maximum time to |
| 383 | wait. |
| 384 | |
| 385 | """ |
| 386 | endtime = None |
| 387 | waittime = timeout |
| 388 | result = predicate() |
| 389 | while not result: |
| 390 | if waittime is not None: |
| 391 | if endtime is None: |
| 392 | endtime = _time() + waittime |
| 393 | else: |
| 394 | waittime = endtime - _time() |
| 395 | if waittime <= 0: |
| 396 | break |
| 397 | self.wait(waittime) |
| 398 | result = predicate() |
| 399 | return result |
| 400 | |
| 401 | def notify(self, n=1): |
| 402 | """Wake up one or more threads waiting on this condition, if any. |