forked from platypush/platypush
Added StoppableThread
common interface.
This commit is contained in:
parent
2f49ddf33a
commit
4b4db5b3c7
2 changed files with 28 additions and 3 deletions
|
@ -4,6 +4,8 @@ import os
|
||||||
|
|
||||||
from platypush.utils.manifest import Manifest
|
from platypush.utils.manifest import Manifest
|
||||||
|
|
||||||
|
from ._types import StoppableThread
|
||||||
|
|
||||||
logger = logging.getLogger('platypush')
|
logger = logging.getLogger('platypush')
|
||||||
|
|
||||||
|
|
||||||
|
@ -26,9 +28,20 @@ class ExtensionWithManifest:
|
||||||
self._manifest = self.get_manifest()
|
self._manifest = self.get_manifest()
|
||||||
|
|
||||||
def get_manifest(self) -> Manifest:
|
def get_manifest(self) -> Manifest:
|
||||||
manifest_file = os.path.join(os.path.dirname(inspect.getfile(self.__class__)), 'manifest.yaml')
|
manifest_file = os.path.join(
|
||||||
assert os.path.isfile(manifest_file), (
|
os.path.dirname(inspect.getfile(self.__class__)), 'manifest.yaml'
|
||||||
'The extension {} has no associated manifest.yaml'.format(self.__class__.__name__)
|
)
|
||||||
|
assert os.path.isfile(
|
||||||
|
manifest_file
|
||||||
|
), 'The extension {} has no associated manifest.yaml'.format(
|
||||||
|
self.__class__.__name__
|
||||||
)
|
)
|
||||||
|
|
||||||
return Manifest.from_file(manifest_file)
|
return Manifest.from_file(manifest_file)
|
||||||
|
|
||||||
|
|
||||||
|
__all__ = [
|
||||||
|
'ExtensionWithManifest',
|
||||||
|
'StoppableThread',
|
||||||
|
'exec_wrapper',
|
||||||
|
]
|
||||||
|
|
12
platypush/common/_types.py
Normal file
12
platypush/common/_types.py
Normal 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):
|
||||||
|
...
|
Loading…
Reference in a new issue