From b2f720da67bf3d9f94cea0e9ed7e7e71fda1d995 Mon Sep 17 00:00:00 2001 From: Sebastien Bourdeauducq Date: Sat, 1 Aug 2015 19:52:13 +0800 Subject: [PATCH] gui: better state error handling Remains limited by issue pyqtgraph/pyqtgraph#204 --- artiq/gui/state.py | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/artiq/gui/state.py b/artiq/gui/state.py index 9c5e7b8bb..9088da4e6 100644 --- a/artiq/gui/state.py +++ b/artiq/gui/state.py @@ -1,10 +1,14 @@ import asyncio from collections import OrderedDict +import logging from artiq.tools import TaskObject from artiq.protocols import pyon +logger = logging.getLogger(__name__) + + # support Qt CamelCase naming scheme for save/restore state def _save_state(obj): method = getattr(obj, "save_state", None) @@ -38,6 +42,8 @@ class StateManager(TaskObject): try: data = pyon.load_file(self.filename) except FileNotFoundError: + logger.info("State database '%s' not found, using defaults", + self.filename) return # The state of one object may depend on the state of another, # e.g. the display state may create docks that are referenced in @@ -47,10 +53,20 @@ class StateManager(TaskObject): for name, obj in reversed(list(self.stateful_objects.items())): state = data.get(name, None) if state is not None: - _restore_state(obj, state) + try: + _restore_state(obj, state) + except: + logger.warning("Failed to restore state for object '%s'", + name, exc_info=True) def save(self): - data = {k: _save_state(v) for k, v in self.stateful_objects.items()} + data = dict() + for k, v in self.stateful_objects.items(): + try: + data[k] = _save_state(v) + except: + logger.warning("Failed to save state for object '%s'", k, + exc_info=True) pyon.store_file(self.filename, data) @asyncio.coroutine