explicitly stop statemachine threads
This commit is contained in:
parent
24fbb4b707
commit
5f39139b7c
|
@ -37,8 +37,9 @@ class Blinkenlights(ExceptionThread):
|
||||||
logger.debug('Starting LED on pin %s', self._pin)
|
logger.debug('Starting LED on pin %s', self._pin)
|
||||||
|
|
||||||
def stop(self):
|
def stop(self):
|
||||||
self._stopper.set()
|
if self.is_alive():
|
||||||
logger.debug('Stopping LED on pin %s', self._pin)
|
self._stopper.set()
|
||||||
|
logger.debug('Stopping LED on pin %s', self._pin)
|
||||||
|
|
||||||
def setCyclePeriod(self, cyclePeriod):
|
def setCyclePeriod(self, cyclePeriod):
|
||||||
self._sleeptime = cyclePeriod/20/2
|
self._sleeptime = cyclePeriod/20/2
|
||||||
|
|
26
listeners.py
26
listeners.py
|
@ -118,6 +118,16 @@ class KeypadListener:
|
||||||
self._listener.start()
|
self._listener.start()
|
||||||
logger.debug('Started keypad listener')
|
logger.debug('Started keypad listener')
|
||||||
|
|
||||||
|
def stop(self):
|
||||||
|
try:
|
||||||
|
self._dev.ungrab()
|
||||||
|
self._dev = None
|
||||||
|
logger.debug('Released keypad device')
|
||||||
|
except IOError:
|
||||||
|
logger.error('Failed to release keypad device')
|
||||||
|
except AttributeError:
|
||||||
|
pass
|
||||||
|
|
||||||
def resetBuffer(self):
|
def resetBuffer(self):
|
||||||
self._stopResetCountdown
|
self._stopResetCountdown
|
||||||
self._clearBuffer()
|
self._clearBuffer()
|
||||||
|
@ -134,13 +144,7 @@ class KeypadListener:
|
||||||
self._buf = ''
|
self._buf = ''
|
||||||
|
|
||||||
def __del__(self):
|
def __del__(self):
|
||||||
try:
|
self.stop()
|
||||||
self._dev.ungrab()
|
|
||||||
logger.debug('Released keypad device')
|
|
||||||
except IOError:
|
|
||||||
logger.error('Failed to release keypad device')
|
|
||||||
except AttributeError:
|
|
||||||
pass
|
|
||||||
|
|
||||||
class PipeListener(ExceptionThread):
|
class PipeListener(ExceptionThread):
|
||||||
'''
|
'''
|
||||||
|
@ -177,9 +181,13 @@ class PipeListener(ExceptionThread):
|
||||||
ExceptionThread.start(self)
|
ExceptionThread.start(self)
|
||||||
logger.debug('Started pipe listener at path %s', self._path)
|
logger.debug('Started pipe listener at path %s', self._path)
|
||||||
|
|
||||||
def __del__(self):
|
def stop(self):
|
||||||
try:
|
try:
|
||||||
os.remove(self._path)
|
os.remove(self._path)
|
||||||
|
logger.debug('Cleaned up pipe listener at path %s', self._path)
|
||||||
except FileNotFoundError:
|
except FileNotFoundError:
|
||||||
pass
|
pass
|
||||||
logger.debug('Cleaned up pipe listener at path %s', self._path)
|
|
||||||
|
def __del__(self):
|
||||||
|
self.stop()
|
||||||
|
|
||||||
|
|
11
soundLib.py
11
soundLib.py
|
@ -91,6 +91,12 @@ class SoundLib:
|
||||||
|
|
||||||
def start(self):
|
def start(self):
|
||||||
self._startMonitor()
|
self._startMonitor()
|
||||||
|
|
||||||
|
def stop(self):
|
||||||
|
self._stopMonitor()
|
||||||
|
self._ttsSounds.clear()
|
||||||
|
# this sometimes casues "Fatal Python error: (pygame parachute) Segmentation Fault"
|
||||||
|
mixer.quit()
|
||||||
|
|
||||||
def changeVolume(self, volumeDelta):
|
def changeVolume(self, volumeDelta):
|
||||||
newVolume = self.volume + volumeDelta
|
newVolume = self.volume + volumeDelta
|
||||||
|
@ -194,7 +200,4 @@ class SoundLib:
|
||||||
logger.debug('Stopping TTS Queue Monitor')
|
logger.debug('Stopping TTS Queue Monitor')
|
||||||
|
|
||||||
def __del__(self):
|
def __del__(self):
|
||||||
self._stopMonitor()
|
self.stop()
|
||||||
self._ttsSounds.clear()
|
|
||||||
# this sometimes casues "Fatal Python error: (pygame parachute) Segmentation Fault"
|
|
||||||
mixer.quit()
|
|
||||||
|
|
|
@ -204,6 +204,11 @@ class StateMachine:
|
||||||
self.currentState.entry()
|
self.currentState.entry()
|
||||||
|
|
||||||
def __exit__(self, exception_type, exception_value, traceback):
|
def __exit__(self, exception_type, exception_value, traceback):
|
||||||
|
for i in ['LED', 'camera', 'fileDump', 'soundLib', 'secretListener', 'keypadListener']:
|
||||||
|
try:
|
||||||
|
getattr(self, i).stop()
|
||||||
|
except AttributeError:
|
||||||
|
pass
|
||||||
for i in ['LED', 'camera', 'fileDump', 'soundLib', 'secretListener', 'keypadListener']:
|
for i in ['LED', 'camera', 'fileDump', 'soundLib', 'secretListener', 'keypadListener']:
|
||||||
try:
|
try:
|
||||||
getattr(self, i).__del__()
|
getattr(self, i).__del__()
|
||||||
|
|
Loading…
Reference in New Issue