Added StoppableThread common interface.

This commit is contained in:
Fabio Manganiello 2023-03-24 15:40:16 +01:00
parent 2f49ddf33a
commit 4b4db5b3c7
Signed by: blacklight
GPG key ID: D90FBA7F76362774
2 changed files with 28 additions and 3 deletions

View file

@ -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',
]

View file

@ -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):
...