MCPcopy Create free account
hub / github.com/AstroPrint/AstroBox / _threadRun

Method _threadRun

src/astroprint/camera/__init__.py:126–155  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

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:

Callers

nothing calls this directly

Calls 3

_onInactiveMethod · 0.80
waitMethod · 0.45
errorMethod · 0.45

Tested by

no test coverage detected