Browse Source

Reintroduce restarting the UI process on magic return codes.

Fix some unclean shut downs.
looper
Ben Niemann 6 years ago
parent
commit
7aeeffd4c8
  1. 2
      noisicaa/core/process_manager.py
  2. 30
      noisicaa/editor_main.py
  3. 14
      noisicaa/ui/editor_app.py
  4. 4
      noisicaa/ui/ui_process.py

2
noisicaa/core/process_manager.py

@ -286,7 +286,7 @@ class ProcessImpl(object):
asyncio.set_event_loop(self.event_loop)
try:
self.event_loop.run_until_complete(
return self.event_loop.run_until_complete(
self.main_async(ready_callback, *args, **kwargs))
finally:
self.event_loop.stop()

30
noisicaa/editor_main.py

@ -12,14 +12,36 @@ from .runtime_settings import RuntimeSettings
from . import logging
from .core import process_manager
logger = logging.getLogger(__name__)
async def main_async(event_loop, runtime_settings, paths):
manager = process_manager.ProcessManager(event_loop)
async with manager:
proc = await manager.start_process(
'ui', 'noisicaa.ui.ui_process.UIProcess',
runtime_settings=runtime_settings, paths=paths)
await proc.wait()
while True:
proc = await manager.start_process(
'ui', 'noisicaa.ui.ui_process.UIProcess',
runtime_settings=runtime_settings, paths=paths)
await proc.wait()
if proc.returncode == EXIT_RESTART:
runtime_settings.start_clean = False
elif proc.returncode == EXIT_RESTART_CLEAN:
runtime_settings.start_clean = True
elif (proc.returncode != EXIT_SUCCESS
and runtime_settings.dev_mode):
runtime_settings.start_clean = False
delay = next_retry - time.time()
if delay > 0:
logger.warn(
"Sleeping %.1fsec before restarting.", delay)
await asyncio.sleep(delay)
else:
return proc.returncode
def main(argv):

14
noisicaa/ui/editor_app.py

@ -32,10 +32,10 @@ class ExceptHook(object):
def __call__(self, exc_type, exc_value, tb):
if issubclass(exc_type, RestartAppException):
self.app.exit(EXIT_RESTART)
self.app.quit(EXIT_RESTART)
return
if issubclass(exc_type, RestartAppCleanException):
self.app.exit(EXIT_RESTART_CLEAN)
self.app.quit(EXIT_RESTART_CLEAN)
return
msg = ''.join(traceback.format_exception(exc_type, exc_value, tb))
@ -74,7 +74,6 @@ class BaseEditorApp(QApplication):
self._projects = []
self._exit_code = None
self.default_style = None
self.sequencer = None
@ -116,8 +115,8 @@ class BaseEditorApp(QApplication):
self.sequencer.close()
self.sequencer = None
def quit(self):
self.process.quit()
def quit(self, exit_code=0):
self.process.quit(exit_code)
def createSequencer(self):
return None
@ -125,11 +124,6 @@ class BaseEditorApp(QApplication):
def createMidiHub(self):
return devices.MidiHub(self.sequencer)
def exit(self, exit_code=0):
logger.info("exit(%d) received", exit_code)
self._exit_code = exit_code
super().exit(exit_code)
def dumpSettings(self):
for key in self.settings.allKeys():
value = self.settings.value(key)

4
noisicaa/ui/ui_process.py

@ -46,8 +46,10 @@ class UIProcessMixin(object):
async def run(self):
await self._shutting_down.wait()
return self.exit_code
def quit(self):
def quit(self, exit_code=0):
self.exit_code = exit_code
self._shutting_down.set()

Loading…
Cancel
Save