(self)
| 124 | self._logger.warn('Already running') |
| 125 | |
| 126 | def _threadRun(self): |
| 127 | self.lastActivity = time.time() |
| 128 | waitForSecs = self._inactivitySecs |
| 129 | |
| 130 | try: |
| 131 | while not self._stopped: |
| 132 | self._logger.debug('Waiting %f seconds' % waitForSecs) |
| 133 | if not self._inactivtyEvent.wait(waitForSecs): |
| 134 | if not self._stopped: |
| 135 | secsSinceLastActivity = time.time() - self.lastActivity |
| 136 | self._logger.debug('%f seconds since last activity' % secsSinceLastActivity) |
| 137 | if secsSinceLastActivity >= self._inactivitySecs: |
| 138 | # it's possible that onInactive detects that video is playing. In that case |
| 139 | # we reset the time again so we can check later, as the camera was active on this check. |
| 140 | # If not, onInactive will call close_camera which will stop this thread and not |
| 141 | # wait anymore |
| 142 | waitForSecs = self._inactivitySecs |
| 143 | self.lastActivity = time.time() |
| 144 | |
| 145 | try: |
| 146 | self._onInactive() |
| 147 | |
| 148 | except Exception as e: |
| 149 | self._logger.error('Error while processing inactivity event: %s' % e, exc_info=True) |
| 150 | |
| 151 | else: |
| 152 | waitForSecs = self._inactivitySecs - secsSinceLastActivity |
| 153 | |
| 154 | finally: |
| 155 | self._thread = None |
| 156 | |
| 157 | def stop(self): |
| 158 | if self._thread: |
nothing calls this directly
no test coverage detected