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

View File

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

View File

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

View File

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