1
0
mirror of https://github.com/dkmstr/openuds.git synced 2024-12-22 13:34:04 +03:00

Fix tunnel removal procedure on Mac Launcher

This commit is contained in:
Adolfo Gómez García 2023-05-23 02:25:35 +02:00
parent 23a9465ae1
commit 45a4dec18f
No known key found for this signature in database
GPG Key ID: DD1ABF20724CDA23

View File

@ -11,6 +11,7 @@ from PyQt5 import QtCore, QtWidgets, QtGui
SCRIPT_NAME = 'UDSClientLauncher' SCRIPT_NAME = 'UDSClientLauncher'
class UdsApplication(QtWidgets.QApplication): class UdsApplication(QtWidgets.QApplication):
path: str path: str
tunnels: typing.List[subprocess.Popen] tunnels: typing.List[subprocess.Popen]
@ -22,6 +23,10 @@ class UdsApplication(QtWidgets.QApplication):
self.lastWindowClosed.connect(self.closeTunnels) # type: ignore self.lastWindowClosed.connect(self.closeTunnels) # type: ignore
def cleanTunnels(self) -> None: def cleanTunnels(self) -> None:
'''
Removes all finished tunnels from the list
'''
def isRunning(p: subprocess.Popen): def isRunning(p: subprocess.Popen):
try: try:
if p.poll() is None: if p.poll() is None:
@ -30,13 +35,13 @@ class UdsApplication(QtWidgets.QApplication):
logger.debug('Got error polling subprocess: %s', e) logger.debug('Got error polling subprocess: %s', e)
return False return False
for k in [i for i, tunnel in enumerate(self.tunnels) if not isRunning(tunnel)]: # Remove references to finished tunnels, they will be garbage collected
try: self.tunnels = [tunnel for tunnel in self.tunnels if isRunning(tunnel)]
del self.tunnels[k]
except Exception as e:
logger.debug('Error closing tunnel: %s', e)
def closeTunnels(self) -> None: def closeTunnels(self) -> None:
'''
Finishes all running tunnels
'''
logger.debug('Closing remaining tunnels') logger.debug('Closing remaining tunnels')
for tunnel in self.tunnels: for tunnel in self.tunnels:
logger.debug('Checking %s - "%s"', tunnel, tunnel.poll()) logger.debug('Checking %s - "%s"', tunnel, tunnel.poll())
@ -70,6 +75,6 @@ def main(args: typing.List[str]):
sys.exit(app.exec()) sys.exit(app.exec())
if __name__ == "__main__": if __name__ == "__main__":
main(args=sys.argv) main(args=sys.argv)