improve multiprocessing, wait for complete and handle remtoe moregraceful
This commit is contained in:
parent
59c4a2beb4
commit
05165d2868
@ -195,7 +195,7 @@ driver=unixDriver
|
||||
# tcp port
|
||||
port=22447
|
||||
# socket filepath
|
||||
socketpath=/tmp/
|
||||
socketFile=
|
||||
# allow settings to overwrite
|
||||
enableSettingsRemote=True
|
||||
# allow commands to be executed
|
||||
|
@ -205,7 +205,7 @@ driver=unixDriver
|
||||
# tcp port
|
||||
port=22447
|
||||
# socket filepath
|
||||
socketpath=/tmp/
|
||||
socketFile=
|
||||
# allow settings to overwrite
|
||||
enableSettingsRemote=True
|
||||
# allow commands to be executed
|
||||
|
@ -205,7 +205,7 @@ driver=unixDriver
|
||||
# tcp port
|
||||
port=22447
|
||||
# socket filepath
|
||||
socketpath=/tmp/
|
||||
socketFile=
|
||||
# allow settings to overwrite
|
||||
enableSettingsRemote=True
|
||||
# allow commands to be executed
|
||||
|
@ -206,7 +206,7 @@ driver=unixDriver
|
||||
# tcp port
|
||||
port=22447
|
||||
# socket filepath
|
||||
socketpath=/tmp/
|
||||
socketFile=
|
||||
# allow settings to overwrite
|
||||
enableSettingsRemote=True
|
||||
# allow commands to be executed
|
||||
|
@ -206,7 +206,7 @@ driver=unixDriver
|
||||
# tcp port
|
||||
port=22447
|
||||
# socket filepath
|
||||
socketpath=/tmp/
|
||||
socketFile=
|
||||
# allow settings to overwrite
|
||||
enableSettingsRemote=True
|
||||
# allow commands to be executed
|
||||
|
@ -151,7 +151,7 @@ driver=unixDriver
|
||||
# tcp port
|
||||
port=22447
|
||||
# socket filepath
|
||||
socketpath=/tmp/
|
||||
socketFile=
|
||||
# allow settings to overwrite
|
||||
enableSettingsRemote=True
|
||||
# allow commands to be executed
|
||||
|
@ -205,7 +205,7 @@ driver=unixDriver
|
||||
# tcp port
|
||||
port=22447
|
||||
# socket filepath
|
||||
socketpath=/tmp/
|
||||
socketFile=
|
||||
# allow settings to overwrite
|
||||
enableSettingsRemote=True
|
||||
# allow commands to be executed
|
||||
|
@ -23,15 +23,15 @@ class processManager():
|
||||
|
||||
def terminateAllProcesses(self):
|
||||
for proc in self._Processes:
|
||||
try:
|
||||
proc.terminate()
|
||||
except KeyboardInterrupt:
|
||||
pass
|
||||
except:
|
||||
pass
|
||||
proc.join()
|
||||
#try:
|
||||
# proc.terminate()
|
||||
#except KeyboardInterrupt:
|
||||
# pass
|
||||
#except:
|
||||
# pass
|
||||
proc.join()
|
||||
for t in self._Threads:
|
||||
t.join()
|
||||
t.join()
|
||||
def heartBeatTimer(self, active):
|
||||
try:
|
||||
time.sleep(0.5)
|
||||
|
@ -84,7 +84,7 @@ settingsData = {
|
||||
'enabled': True,
|
||||
'driver': 'unixDriver',
|
||||
'port': 22447,
|
||||
'socketpath':'/tmp/',
|
||||
'socketFile':'',
|
||||
'enableSettingsRemote': True,
|
||||
'enableCommandRemote': True,
|
||||
},
|
||||
|
@ -18,30 +18,36 @@ class driver(remoteDriver):
|
||||
self.env['runtime']['processManager'].addCustomEventThread(self.watchDog, multiprocess=True)
|
||||
def watchDog(self, active, eventQueue):
|
||||
# echo "command say this is a test" | nc localhost 22447
|
||||
self.sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
||||
self.sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
|
||||
self.fenrirSock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
||||
self.fenrirSock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
|
||||
self.host = '127.0.0.1'
|
||||
self.port = self.env['runtime']['settingsManager'].getSettingAsInt('remote', 'port')
|
||||
self.sock.bind((self.host, self.port))
|
||||
self.sock.listen(1)
|
||||
self.fenrirSock.bind((self.host, self.port))
|
||||
self.fenrirSock.listen(1)
|
||||
while active.value == 1:
|
||||
client_sock, client_addr = self.sock.accept()
|
||||
if client_sock:
|
||||
# Check if the client is still connected and if data is available:
|
||||
try:
|
||||
r, w, e = select.select([client_sock,], [], [])
|
||||
except select.error:
|
||||
return
|
||||
if len(r) > 0:
|
||||
rawdata = client_sock.recv(8129)
|
||||
try:
|
||||
data = rawdata.decode("utf-8").rstrip().lstrip()
|
||||
eventQueue.put({"Type":fenrirEventType.RemoteIncomming,
|
||||
"Data": data
|
||||
})
|
||||
except:
|
||||
pass
|
||||
try:
|
||||
r, _, _ = select.select([self.fenrirSock], [], [], 0.8)
|
||||
except select.error:
|
||||
break
|
||||
if r == []:
|
||||
continue
|
||||
if self.fenrirSock in r:
|
||||
client_sock, client_addr = self.fenrirSock.accept()
|
||||
try:
|
||||
rawdata = client_sock.recv(8129)
|
||||
except:
|
||||
pass
|
||||
try:
|
||||
data = rawdata.decode("utf-8").rstrip().lstrip()
|
||||
eventQueue.put({"Type":fenrirEventType.RemoteIncomming,
|
||||
"Data": data
|
||||
})
|
||||
except:
|
||||
pass
|
||||
try:
|
||||
client_sock.close()
|
||||
if self.sock:
|
||||
self.sock.close()
|
||||
self.sock = None
|
||||
except:
|
||||
pass
|
||||
if self.fenrirSock:
|
||||
self.fenrirSock.close()
|
||||
self.fenrirSock = None
|
||||
|
@ -19,39 +19,49 @@ class driver(remoteDriver):
|
||||
self.env['runtime']['processManager'].addCustomEventThread(self.watchDog, multiprocess=True)
|
||||
def watchDog(self, active, eventQueue):
|
||||
# echo "command say this is a test" | socat - UNIX-CLIENT:/tmp/fenrirscreenreader-deamon.sock
|
||||
|
||||
if self.env['runtime']['settingsManager'].getSetting('screen', 'driver') =='vcsaDriver':
|
||||
socketpath = self.env['runtime']['settingsManager'].getSettingAsInt('remote', 'socketpath') + 'fenrirscreenreader-deamon.sock'
|
||||
else:
|
||||
socketpath = self.env['runtime']['settingsManager'].getSettingAsInt('remote', 'socketpath') + 'fenrirscreenreader-' + str(os.getpid()) + '.sock'
|
||||
if os.path.exists(socketpath):
|
||||
os.remove(socketpath)
|
||||
self.sock = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
|
||||
self.sock.bind(socketpath)
|
||||
self.sock.listen(1)
|
||||
if self.env['runtime']['settingsManager'].getSetting('screen', 'driver') =='vcsaDriver':
|
||||
os.chmod(socketpath, 0o222)
|
||||
while active.value == 1:
|
||||
client_sock, client_addr = self.sock.accept()
|
||||
if client_sock:
|
||||
# Check if the client is still connected and if data is available:
|
||||
try:
|
||||
r, w, e = select.select([client_sock,], [], [])
|
||||
except select.error:
|
||||
return
|
||||
if len(r) > 0:
|
||||
rawdata = client_sock.recv(8129)
|
||||
try:
|
||||
data = rawdata.decode("utf-8").rstrip().lstrip()
|
||||
eventQueue.put({"Type":fenrirEventType.RemoteIncomming,
|
||||
"Data": data
|
||||
})
|
||||
except:
|
||||
pass
|
||||
socketFile = ''
|
||||
try:
|
||||
socketFile = self.env['runtime']['settingsManager'].getSetting('remote', 'socketFile')
|
||||
except:
|
||||
pass
|
||||
if socketFile == '':
|
||||
if self.env['runtime']['settingsManager'].getSetting('screen', 'driver') =='vcsaDriver':
|
||||
socketFile = '/tmp/fenrirscreenreader-deamon.sock'
|
||||
else:
|
||||
socketFile = '/tmp/fenrirscreenreader-' + str(os.getppid()) + '.sock'
|
||||
if os.path.exists(socketFile):
|
||||
os.unlink(socketFile)
|
||||
self.fenrirSock = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
|
||||
self.fenrirSock.bind(socketFile)
|
||||
os.chmod(socketFile, 0o222)
|
||||
self.fenrirSock.listen(1)
|
||||
while active.value:
|
||||
# Check if the client is still connected and if data is available:
|
||||
try:
|
||||
r, _, _ = select.select([self.fenrirSock], [], [], 0.8)
|
||||
except select.error:
|
||||
break
|
||||
if r == []:
|
||||
continue
|
||||
if self.fenrirSock in r:
|
||||
client_sock, client_addr = self.fenrirSock.accept()
|
||||
try:
|
||||
rawdata = client_sock.recv(8129)
|
||||
except:
|
||||
pass
|
||||
try:
|
||||
data = rawdata.decode("utf-8").rstrip().lstrip()
|
||||
eventQueue.put({"Type":fenrirEventType.RemoteIncomming,
|
||||
"Data": data
|
||||
})
|
||||
except:
|
||||
pass
|
||||
try:
|
||||
client_sock.close()
|
||||
|
||||
if os.path.exists(socketpath):
|
||||
os.remove(socketpath)
|
||||
if self.sock:
|
||||
self.sock.close()
|
||||
self.sock = None
|
||||
except:
|
||||
pass
|
||||
if self.fenrirSock:
|
||||
self.fenrirSock.close()
|
||||
self.fenrirSock = None
|
||||
if os.path.exists(socketFile):
|
||||
os.unlink(socketFile)
|
||||
|
@ -179,13 +179,13 @@ class driver(screenDriver):
|
||||
try:
|
||||
msgBytes = self.readAll(sys.stdin.fileno(), len=4096)
|
||||
except (EOFError, OSError):
|
||||
active.value = False
|
||||
eventQueue.put({"Type":fenrirEventType.StopMainLoop,"Data":None})
|
||||
break
|
||||
if self.shortcutType == 'KEY':
|
||||
try:
|
||||
self.injectTextToScreen(msgBytes)
|
||||
except:
|
||||
active.value = False
|
||||
eventQueue.put({"Type":fenrirEventType.StopMainLoop,"Data":None})
|
||||
break
|
||||
else:
|
||||
eventQueue.put({"Type":fenrirEventType.ByteInput,
|
||||
@ -195,7 +195,7 @@ class driver(screenDriver):
|
||||
try:
|
||||
msgBytes = self.readAll(self.p_out.fileno(), interruptFd=sys.stdin.fileno())
|
||||
except (EOFError, OSError):
|
||||
active.value = False
|
||||
eventQueue.put({"Type":fenrirEventType.StopMainLoop,"Data":None})
|
||||
break
|
||||
# feed and send event bevore write, the pyte already has the right state
|
||||
# so fenrir already can progress bevore os.write what should give some better reaction time
|
||||
@ -206,7 +206,7 @@ class driver(screenDriver):
|
||||
self.injectTextToScreen(msgBytes, screen=sys.stdout.fileno())
|
||||
except Exception as e: # Process died?
|
||||
print(e)
|
||||
active.value = False
|
||||
eventQueue.put({"Type":fenrirEventType.StopMainLoop,"Data":None})
|
||||
finally:
|
||||
os.kill(self.p_pid, signal.SIGTERM)
|
||||
self.p_out.close()
|
||||
|
Loading…
Reference in New Issue
Block a user