Browse Source

Quit attached GUI when external nsmd closed in the meanwhile. Instead of a freeze

master
Nils 2 years ago
parent
commit
ec9b0ce787
  1. 1
      engine/api.py
  2. 24
      engine/nsmservercontrol.py
  3. 3
      qtgui/mainwindow.py

1
engine/api.py

@ -109,7 +109,6 @@ class Callbacks(object):
This will also fire if we start and detect that a session is already open and running.
"""
for func in self.sessionOpenReady:
print (func)
func(nsmSessionExportDict)
def _sessionOpenLoading(self, nsmSessionExportDict):

24
engine/nsmservercontrol.py

@ -471,7 +471,26 @@ class NsmServerControl(object):
def _setPause(self, state:bool):
"""Set both the socket and the thread into waiting mode or not.
With this we can wait for answers until we resume async operation"""
With this we can wait for answers until we resume async operation
This is a potential freeze/lock operation if we make a request to an
external nsmd, which already closed.
We will check if the socket is still open before going into blocking mode.
"""
if not self.ourOwnServer and not self._isNsmdRunning(self.nsmOSCUrl): #see docstring
#Try to clean up
try:
self.sock.shutdown(2)
except:
pass
try:
self.sock.close()
except:
pass
#This is a reason to let the program exit.
logger.error("Wanted to do a blocking call but external nsmd found not running anymore. It probably closed or crashed. Will close our GUI now. There is no risk of data loss because we were just an attached GUI anyway.")
sysexit() #return None switch to return None to let it crash and see the python traceback
if state:
self.sock.setblocking(True) #explicitly wait.
self.sock.settimeout(0.5)
@ -527,8 +546,10 @@ class NsmServerControl(object):
if msg:
self._queue.append(msg)
except BlockingIOError: #happens while no data is received. Has nothing to do with blocking or not.
#If we lose connection to nsmd (because it was killed remotely) this will stop as well.
break
except socket.timeout:
#Try again next time.
break
for msg in self._queue:
@ -604,7 +625,6 @@ class NsmServerControl(object):
Returns list of arguments, can be empty.
"""
assert not self._queue, [(m.oscpath, m.params) for m in self._queue]
logger.info(f"[wait for answer]: Sending {path}: {arguments}")
self._setPause(True)
out_msg = _OutgoingMessage(path)

3
qtgui/mainwindow.py

@ -404,8 +404,7 @@ class MainWindow(QtWidgets.QMainWindow):
result = True
if result:
self.storeWindowSettings()
self._callSysExit()
self._callSysExit() #contains self.storeWindowSettings
def closeEvent(self, event):
"""Window manager close.

Loading…
Cancel
Save