improve processing

This commit is contained in:
chrys 2017-08-03 22:46:58 +02:00
parent cd5e042768
commit c92ded42ba
4 changed files with 35 additions and 31 deletions

View File

@ -151,8 +151,10 @@ class fenrirManager():
self.environment['runtime']['eventManager'].putToEventQueue(fenrirEventType.ExecuteCommand, self.command) self.environment['runtime']['eventManager'].putToEventQueue(fenrirEventType.ExecuteCommand, self.command)
self.command = '' self.command = ''
def shutdownRequest(self): def shutdownRequest(self):
self.environment['runtime']['eventManager'].stopMainEventLoop() try:
self.environment['runtime']['eventManager'].stopMainEventLoop()
except:
pass
def captureSignal(self, siginit, frame): def captureSignal(self, siginit, frame):
self.shutdownRequest() self.shutdownRequest()
@ -161,8 +163,11 @@ class fenrirManager():
self.environment['runtime']['outputManager'].presentText(_("Quit Fenrir"), soundIcon='ScreenReaderOff', interrupt=True) self.environment['runtime']['outputManager'].presentText(_("Quit Fenrir"), soundIcon='ScreenReaderOff', interrupt=True)
self.environment['runtime']['eventManager'].cleanEventQueue() self.environment['runtime']['eventManager'].cleanEventQueue()
self.environment['runtime']['eventManager'].stopMainEventLoop(True) self.environment['runtime']['eventManager'].stopMainEventLoop(True)
time.sleep(1)
for currManager in self.environment['general']['managerList']: for currManager in self.environment['general']['managerList']:
if self.environment['runtime'][currManager]: if self.environment['runtime'][currManager]:
self.environment['runtime'][currManager].shutdown() self.environment['runtime'][currManager].shutdown()
del self.environment['runtime'][currManager] del self.environment['runtime'][currManager]
self.environment = None self.environment = None

View File

@ -11,8 +11,8 @@ generalData = {
'tutorialMode': False, 'tutorialMode': False,
'currUser':'', 'currUser':'',
'prevUser':'', 'prevUser':'',
'managerList':['processManager','eventManager','punctuationManager','cursorManager','applicationManager','commandManager' 'managerList':['processManager','punctuationManager','cursorManager','applicationManager','commandManager'
,'screenManager','inputManager','outputManager','helpManager','debug'], ,'screenManager','inputManager','outputManager','helpManager','eventManager','debug'],
'commandFolderList':['commands','onInput', 'onCursorChange', 'onScreenUpdate','onScreenChanged','onHeartBeat', 'onPlugInputDevice' 'commandFolderList':['commands','onInput', 'onCursorChange', 'onScreenUpdate','onScreenChanged','onHeartBeat', 'onPlugInputDevice'
,'onApplicationChange','onSwitchApplicationProfile','help',], ,'onApplicationChange','onSwitchApplicationProfile','help',],
} }

View File

@ -19,23 +19,22 @@ class processManager():
def initialize(self, environment): def initialize(self, environment):
self.env = environment self.env = environment
self.running = self.env['runtime']['eventManager'].getMainLoopRunning() self.running = self.env['runtime']['eventManager'].getMainLoopRunning()
self.addSimpleEventThread(fenrirEventType.HeartBeat, self.heartBeatTimer, multiprocess=False) self.addSimpleEventThread(fenrirEventType.HeartBeat, self.heartBeatTimer, multiprocess=True)
def shutdown(self): def shutdown(self):
self.terminateAllProcesses() self.terminateAllProcesses()
def terminateAllProcesses(self):
for proc in self._Processes:
try:
proc.terminate()
except Exception as e:
print(e)
def heartBeatTimer(self, active): def heartBeatTimer(self, active):
try: try:
time.sleep(0.5) time.sleep(0.5)
except: except:
pass pass
return time.time() return time.time()
def terminateAllProcesses(self):
time.sleep(1)
for proc in self._Processes:
try:
proc.terminate()
except Exception as e:
print(e)
def addCustomEventThread(self, function, pargs = None, multiprocess = False, runOnce = False): def addCustomEventThread(self, function, pargs = None, multiprocess = False, runOnce = False):
eventQueue = self.env['runtime']['eventManager'].getEventQueue() eventQueue = self.env['runtime']['eventManager'].getEventQueue()
if multiprocess: if multiprocess:
@ -50,7 +49,7 @@ class processManager():
if multiprocess: if multiprocess:
t = Process(target=self.simpleEventWorkerThread, args=(event, function, pargs, runOnce)) t = Process(target=self.simpleEventWorkerThread, args=(event, function, pargs, runOnce))
self._Processes.append(t) self._Processes.append(t)
else:# thread not implemented yet else:
t = Thread(target=self.simpleEventWorkerThread, args=(event, function, pargs, runOnce)) t = Thread(target=self.simpleEventWorkerThread, args=(event, function, pargs, runOnce))
self._Threads.append(t) self._Threads.append(t)
t.start() t.start()
@ -67,7 +66,7 @@ class processManager():
else: else:
function(self.running, eventQueue) function(self.running, eventQueue)
except Exception as e: except Exception as e:
print(e) self.env['runtime']['debug'].writeDebugOut('processManager:customEventWorkerThread:function():' + str(e),debug.debugLevel.ERROR)
if runOnce: if runOnce:
break break

View File

@ -61,12 +61,10 @@ class driver():
monitor = pyudev.Monitor.from_netlink(context) monitor = pyudev.Monitor.from_netlink(context)
monitor.filter_by(subsystem='input') monitor.filter_by(subsystem='input')
monitor.start() monitor.start()
while active: while active.value == 1:
devices = monitor.poll(2) devices = monitor.poll(2)
if devices: if devices:
eventQueue.put({"Type":fenrirEventType.PlugInputDevice,"Data":''}) eventQueue.put({"Type":fenrirEventType.PlugInputDevice,"Data":''})
#self.env['runtime']['settingsManager'].getSettingAsFloat('screen', 'screenUpdateDelay')
return time.time() return time.time()
def plugInputDeviceWatchdogTimer(self, active): def plugInputDeviceWatchdogTimer(self, active):
time.sleep(2.5) time.sleep(2.5)
@ -75,24 +73,26 @@ class driver():
if not self._initialized: if not self._initialized:
return return
def inputWatchdog(self,active , params): def inputWatchdog(self,active , params):
deviceFd = [] try:
print('WD:',params['dev'],self.watchDog.value == 0) deviceFd = []
while self.watchDog.value == 0: while self.watchDog.value == 0:
if active.value == 0: if active.value == 0:
return return
r = [] r = []
while r == []: while r == []:
deviceFd = list(params['dev']) if active.value == 0:
r, w, x = select(deviceFd, [], [], 2) return
print('select',r, w, x) deviceFd = list(params['dev'])
self.watchDog.value = 0 r, w, x = select(deviceFd, [], [], 2)
self.watchDog.value = 0
except:
pass
def getInputEvent(self): def getInputEvent(self):
if not self.hasIDevices(): if not self.hasIDevices():
self.watchDog.value = 1 self.watchDog.value = 1
return None return None
event = None event = None
r, w, x = select(self.iDevices, [], [], 0.00001) r, w, x = select(self.iDevices, [], [], 0.00001)
print(self.iDevices,'read',r, w, x)
if r != []: if r != []:
for fd in r: for fd in r:
try: try: