Allow async operators to automatically quit when they raise an exception.
Just set the class property `stop_upon_exception=True`.
This commit is contained in:
parent
143456ae1d
commit
887a9cc697
@ -178,6 +178,7 @@ class AsyncModalOperatorMixin:
|
|||||||
log = logging.getLogger('%s.AsyncModalOperatorMixin' % __name__)
|
log = logging.getLogger('%s.AsyncModalOperatorMixin' % __name__)
|
||||||
|
|
||||||
_state = 'INITIALIZING'
|
_state = 'INITIALIZING'
|
||||||
|
stop_upon_exception = False
|
||||||
|
|
||||||
def invoke(self, context, event):
|
def invoke(self, context, event):
|
||||||
context.window_manager.modal_handler_add(self)
|
context.window_manager.modal_handler_add(self)
|
||||||
@ -195,6 +196,10 @@ class AsyncModalOperatorMixin:
|
|||||||
"""
|
"""
|
||||||
return
|
return
|
||||||
|
|
||||||
|
def quit(self):
|
||||||
|
"""Signals the state machine to stop this operator from running."""
|
||||||
|
self._state = 'QUIT'
|
||||||
|
|
||||||
def execute(self, context):
|
def execute(self, context):
|
||||||
return self.invoke(context, None)
|
return self.invoke(context, None)
|
||||||
|
|
||||||
@ -206,6 +211,11 @@ class AsyncModalOperatorMixin:
|
|||||||
if ex is not None:
|
if ex is not None:
|
||||||
self._state = 'EXCEPTION'
|
self._state = 'EXCEPTION'
|
||||||
self.log.error('Exception while running task: %s', ex)
|
self.log.error('Exception while running task: %s', ex)
|
||||||
|
if self.stop_upon_exception:
|
||||||
|
self.quit()
|
||||||
|
self._finish(context)
|
||||||
|
return {'FINISHED'}
|
||||||
|
|
||||||
return {'RUNNING_MODAL'}
|
return {'RUNNING_MODAL'}
|
||||||
|
|
||||||
if self._state == 'QUIT':
|
if self._state == 'QUIT':
|
||||||
|
Reference in New Issue
Block a user