Skip to content

Commit

Permalink
Log any exceptions
Browse files Browse the repository at this point in the history
  • Loading branch information
UuuNyaa committed Jan 8, 2023
1 parent e1014cf commit ed032ee
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 3 deletions.
2 changes: 1 addition & 1 deletion motion_generate_tools/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
bl_info = {
"name": "motion_generate_tools",
"author": "UuuNyaa",
"version": (0, 0, 7),
"version": (0, 0, 8),
"blender": (3, 3, 0),
"location": "View3D > Sidebar > Panel",
"description": "Utility tools for motion generating.",
Expand Down
10 changes: 10 additions & 0 deletions motion_generate_tools/executors.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import subprocess
import sys
import threading
import traceback
from typing import Any, Callable, Iterable, Optional

FinallyCallback = Callable[['FunctionExecutor'], None]
Expand Down Expand Up @@ -49,6 +50,7 @@ def _run_background():
self._return_value = function(*args)
except Exception as exception: # pylint: disable=broad-except
self._exception = exception
self.write_exception(exception, line_callback=line_callback)
finally:
self._is_running = False
_invoke_callback(finally_callback, self)
Expand All @@ -73,6 +75,14 @@ def return_value(self) -> Optional[Any]:
def exception(self) -> Exception:
return self._exception

@staticmethod
def write_exception(exception: Exception, line_callback: Optional[LineCallback]):
if exception is None:
return

for line in (l for f in traceback.format_exception(exception) for l in f.splitlines()):
_invoke_callback(line_callback, line)


class CommandExecutor(FunctionExecutor):
_process: Optional[subprocess.Popen]
Expand Down
4 changes: 2 additions & 2 deletions motion_generate_tools/setup_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,13 +65,13 @@ def is_clip_model_exist() -> bool:
return os.path.isfile(filepaths.CLIP_MODEL_PATH)


def download_clip_model(line_callback: Optional[LineCallback]):
def download_clip_model(line_callback: Optional[LineCallback] = None, finally_callback: Optional[FinallyCallback] = None):
def _run_clip_load():
with _unverify_https_certificates():
import clip # pylint: disable=import-outside-toplevel
clip.load(filepaths.CLIP_MODEL_NAME, device='cpu', jit=False, download_root=filepaths.CLIP_DATA_PATH)

_get_command_executor().exec_function(_run_clip_load, line_callback=line_callback)
_get_command_executor().exec_function(_run_clip_load, line_callback=line_callback, finally_callback=finally_callback)


def delete_clip_model():
Expand Down

0 comments on commit ed032ee

Please sign in to comment.