mirror of
https://github.com/ynput/ayon-core.git
synced 2025-12-24 21:04:40 +01:00
capture errors and add basic handle of the crash
This commit is contained in:
parent
2322d0f2ad
commit
59e49182be
2 changed files with 24 additions and 4 deletions
|
|
@ -192,7 +192,11 @@ class FoldersQtModel(QtGui.QStandardItemModel):
|
|||
or thread_id != self._current_refresh_thread.id
|
||||
):
|
||||
return
|
||||
folder_items, folder_type_items = thread.get_result()
|
||||
if thread.failed:
|
||||
# TODO visualize that refresh failed
|
||||
folder_items, folder_type_items = {}, {}
|
||||
else:
|
||||
folder_items, folder_type_items = thread.get_result()
|
||||
self._fill_items(folder_items, folder_type_items)
|
||||
self._current_refresh_thread = None
|
||||
|
||||
|
|
|
|||
|
|
@ -2,7 +2,10 @@ import os
|
|||
import sys
|
||||
import contextlib
|
||||
import collections
|
||||
import traceback
|
||||
from functools import partial
|
||||
from typing import Union, Any
|
||||
|
||||
|
||||
from qtpy import QtWidgets, QtCore, QtGui
|
||||
import qtawesome
|
||||
|
|
@ -425,26 +428,39 @@ class RefreshThread(QtCore.QThread):
|
|||
self._id = thread_id
|
||||
self._callback = partial(func, *args, **kwargs)
|
||||
self._exception = None
|
||||
self._traceback = None
|
||||
self._result = None
|
||||
self.finished.connect(self._on_finish_callback)
|
||||
|
||||
@property
|
||||
def id(self):
|
||||
def id(self) -> str:
|
||||
return self._id
|
||||
|
||||
@property
|
||||
def failed(self):
|
||||
def failed(self) -> bool:
|
||||
return self._exception is not None
|
||||
|
||||
def run(self):
|
||||
try:
|
||||
self._result = self._callback()
|
||||
except Exception as exc:
|
||||
exc_type, exc_value, exc_traceback = sys.exc_info()
|
||||
err_traceback = "".join(traceback.format_exception(
|
||||
exc_type, exc_value, exc_traceback
|
||||
))
|
||||
print(err_traceback)
|
||||
self._traceback = err_traceback
|
||||
self._exception = exc
|
||||
|
||||
def get_result(self):
|
||||
def get_result(self) -> Any:
|
||||
return self._result
|
||||
|
||||
def get_exception(self) -> Union[BaseException, None]:
|
||||
return self._exception
|
||||
|
||||
def get_traceback(self) -> Union[str, None]:
|
||||
return self._traceback
|
||||
|
||||
def _on_finish_callback(self):
|
||||
"""Trigger custom signal with thread id.
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue