diff --git a/platypush/common/__init__.py b/platypush/common/__init__.py index 04a43b1aa..8a0f84215 100644 --- a/platypush/common/__init__.py +++ b/platypush/common/__init__.py @@ -4,6 +4,8 @@ import os from platypush.utils.manifest import Manifest +from ._types import StoppableThread + logger = logging.getLogger('platypush') @@ -26,9 +28,20 @@ class ExtensionWithManifest: self._manifest = self.get_manifest() def get_manifest(self) -> Manifest: - manifest_file = os.path.join(os.path.dirname(inspect.getfile(self.__class__)), 'manifest.yaml') - assert os.path.isfile(manifest_file), ( - 'The extension {} has no associated manifest.yaml'.format(self.__class__.__name__) + manifest_file = os.path.join( + os.path.dirname(inspect.getfile(self.__class__)), 'manifest.yaml' + ) + assert os.path.isfile( + manifest_file + ), 'The extension {} has no associated manifest.yaml'.format( + self.__class__.__name__ ) return Manifest.from_file(manifest_file) + + +__all__ = [ + 'ExtensionWithManifest', + 'StoppableThread', + 'exec_wrapper', +] diff --git a/platypush/common/_types.py b/platypush/common/_types.py new file mode 100644 index 000000000..b4455e4c2 --- /dev/null +++ b/platypush/common/_types.py @@ -0,0 +1,12 @@ +from abc import ABC, abstractmethod +from threading import Thread + + +class StoppableThread(Thread, ABC): + """ + Base interface for stoppable threads. + """ + + @abstractmethod + def stop(self): + ...