From 0556ecab22c7e7d1ca0d7856c237450ac31422c5 Mon Sep 17 00:00:00 2001 From: Lucy Liu Date: Fri, 10 Nov 2023 16:13:56 +1100 Subject: [PATCH] catch errors when disposing --- src/npe2/_plugin_manager.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/npe2/_plugin_manager.py b/src/npe2/_plugin_manager.py index 1f657d73..df4cda5a 100644 --- a/src/npe2/_plugin_manager.py +++ b/src/npe2/_plugin_manager.py @@ -7,6 +7,7 @@ from collections import Counter from fnmatch import fnmatch from importlib import metadata +from logging import getLogger from pathlib import Path from typing import ( TYPE_CHECKING, @@ -52,6 +53,8 @@ InclusionSet = Union[AbstractSetIntStr, MappingIntStrAny, None] DisposeFunction = Callable[[], None] +logger = getLogger(__name__) + __all__ = ["PluginContext", "PluginManager"] PluginName = str # this is `PluginManifest.name` @@ -710,7 +713,10 @@ def __init__( def _dispose(self): while self._disposables: - self._disposables.pop()() + try: + self._disposables.pop()() + except Exception as e: + logger.warn(f'Error while disposing {self.plugin_key}; {e}') def register_command(self, id: str, command: Optional[Callable] = None): """Associate a callable with a command id."""