explicitly stop statemachine threads

This commit is contained in:
petrucci4prez 2017-06-10 01:52:06 -04:00
parent 24fbb4b707
commit 5f39139b7c
4 changed files with 32 additions and 15 deletions

View File

@ -37,8 +37,9 @@ class Blinkenlights(ExceptionThread):
logger.debug('Starting LED on pin %s', self._pin)
def stop(self):
self._stopper.set()
logger.debug('Stopping LED on pin %s', self._pin)
if self.is_alive():
self._stopper.set()
logger.debug('Stopping LED on pin %s', self._pin)
def setCyclePeriod(self, cyclePeriod):
self._sleeptime = cyclePeriod/20/2

View File

@ -118,6 +118,16 @@ class KeypadListener:
self._listener.start()
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):
self._stopResetCountdown
self._clearBuffer()
@ -134,13 +144,7 @@ class KeypadListener:
self._buf = ''
def __del__(self):
try:
self._dev.ungrab()
logger.debug('Released keypad device')
except IOError:
logger.error('Failed to release keypad device')
except AttributeError:
pass
self.stop()
class PipeListener(ExceptionThread):
'''
@ -177,9 +181,13 @@ class PipeListener(ExceptionThread):
ExceptionThread.start(self)
logger.debug('Started pipe listener at path %s', self._path)
def __del__(self):
def stop(self):
try:
os.remove(self._path)
logger.debug('Cleaned up pipe listener at path %s', self._path)
except FileNotFoundError:
pass
logger.debug('Cleaned up pipe listener at path %s', self._path)
def __del__(self):
self.stop()

View File

@ -91,6 +91,12 @@ class SoundLib:
def start(self):
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):
newVolume = self.volume + volumeDelta
@ -194,7 +200,4 @@ class SoundLib:
logger.debug('Stopping TTS Queue Monitor')
def __del__(self):
self._stopMonitor()
self._ttsSounds.clear()
# this sometimes casues "Fatal Python error: (pygame parachute) Segmentation Fault"
mixer.quit()
self.stop()

View File

@ -204,6 +204,11 @@ class StateMachine:
self.currentState.entry()
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']:
try:
getattr(self, i).__del__()