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