From 887a9cc6979583cf63a2140023831f20a10bfc81 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sybren=20A=2E=20St=C3=BCvel?= Date: Fri, 26 Aug 2016 17:42:20 +0200 Subject: [PATCH] Allow async operators to automatically quit when they raise an exception. Just set the class property `stop_upon_exception=True`. --- blender_cloud/async_loop.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/blender_cloud/async_loop.py b/blender_cloud/async_loop.py index 14d58a3..aeeb67a 100644 --- a/blender_cloud/async_loop.py +++ b/blender_cloud/async_loop.py @@ -178,6 +178,7 @@ class AsyncModalOperatorMixin: log = logging.getLogger('%s.AsyncModalOperatorMixin' % __name__) _state = 'INITIALIZING' + stop_upon_exception = False def invoke(self, context, event): context.window_manager.modal_handler_add(self) @@ -195,6 +196,10 @@ class AsyncModalOperatorMixin: """ return + def quit(self): + """Signals the state machine to stop this operator from running.""" + self._state = 'QUIT' + def execute(self, context): return self.invoke(context, None) @@ -206,6 +211,11 @@ class AsyncModalOperatorMixin: if ex is not None: self._state = 'EXCEPTION' self.log.error('Exception while running task: %s', ex) + if self.stop_upon_exception: + self.quit() + self._finish(context) + return {'FINISHED'} + return {'RUNNING_MODAL'} if self._state == 'QUIT':