From e2fb6de631df94c7346bef95269c621b868c8e50 Mon Sep 17 00:00:00 2001 From: chrys87 Date: Fri, 8 Jul 2016 09:49:59 +0200 Subject: [PATCH] capture ctrl c signal properly and shutdown nicely --- src/fenrir-package/fenrir.py | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/src/fenrir-package/fenrir.py b/src/fenrir-package/fenrir.py index dac42ee2..63ab9e69 100755 --- a/src/fenrir-package/fenrir.py +++ b/src/fenrir-package/fenrir.py @@ -3,7 +3,7 @@ # Fenrir TTY screen reader # By Chrys, Storm Dragon, and contributers. -import os, sys, time +import os, sys, time, signal DEBUG = False @@ -32,7 +32,8 @@ class fenrir(): self.bindings = {} self.autospeak = [] self.soundIcons = {} - + signal.signal(signal.SIGINT, self.captureSignal) + # the following hard coded, in future we have a config loader self.runtime['speechDriverString'] = 'speechd' self.runtime['speechDriver'] = sd.speech() @@ -63,8 +64,14 @@ class fenrir(): self.runtime = self.runtime # command queue here def shutdown(self): - self.threadUpdateScreen.stop() - self.threadHandleInput.stop() + self.runtime['running'] = False + if self.runtime['speechDriver'] != None: + self.runtime['speechDriver'].shutdown() + if self.runtime['debug'] != None: + self.runtime['debug'].closeDebugFile() + + def captureSignal(self, siginit, frame): + self.shutdown() app = fenrir() app.proceed()