Waits until predicate() becomes true. The predicate is invoked with the session locked. If satisfied, the method returns immediately. Otherwise, the lock is released (even if it was held at entry), and the method blocks waiting for some attribute of either self, self
(self, predicate, timeout=None)
| 95 | _sessions_changed.set() |
| 96 | |
| 97 | def wait_for(self, predicate, timeout=None): |
| 98 | """Waits until predicate() becomes true. |
| 99 | |
| 100 | The predicate is invoked with the session locked. If satisfied, the method |
| 101 | returns immediately. Otherwise, the lock is released (even if it was held |
| 102 | at entry), and the method blocks waiting for some attribute of either self, |
| 103 | self.client, self.server, or self.launcher to change. On every change, session |
| 104 | is re-locked and predicate is re-evaluated, until it is satisfied. |
| 105 | |
| 106 | While the session is unlocked, message handlers for components other than |
| 107 | the one that is waiting can run, but message handlers for that one are still |
| 108 | blocked. |
| 109 | |
| 110 | If timeout is not None, the method will unblock and return after that many |
| 111 | seconds regardless of whether the predicate was satisfied. The method returns |
| 112 | False if it timed out, and True otherwise. |
| 113 | """ |
| 114 | |
| 115 | def wait_for_timeout(): |
| 116 | time.sleep(timeout) |
| 117 | wait_for_timeout.timed_out = True |
| 118 | self.notify_changed() |
| 119 | |
| 120 | wait_for_timeout.timed_out = False |
| 121 | if timeout is not None: |
| 122 | thread = threading.Thread( |
| 123 | target=wait_for_timeout, name="Session.wait_for() timeout" |
| 124 | ) |
| 125 | thread.daemon = True |
| 126 | thread.start() |
| 127 | |
| 128 | with self: |
| 129 | while not predicate(): |
| 130 | if wait_for_timeout.timed_out: |
| 131 | return False |
| 132 | self._changed_condition.wait() |
| 133 | return True |
| 134 | |
| 135 | def finalize(self, why, terminate_debuggee=None): |
| 136 | """Finalizes the debug session. |
no test coverage detected