diff --git a/pyobs/modules/robotic/scriptrunner.py b/pyobs/modules/robotic/scriptrunner.py index 82be26e4..c71b7325 100644 --- a/pyobs/modules/robotic/scriptrunner.py +++ b/pyobs/modules/robotic/scriptrunner.py @@ -1,13 +1,18 @@ import logging from typing import Any, Dict -from pyobs.modules import Module +from pyobs.modules import Module, timeout from pyobs.interfaces import IRunnable from pyobs.robotic.scripts import Script log = logging.getLogger(__name__) +async def calc_run_timeout(obj: "ScriptRunner", *args: Any, **kwargs: Any) -> float: + """Calculates timeout for run().""" + return obj.timeout + + class ScriptRunner(Module, IRunnable): """Module for running a script.""" @@ -17,6 +22,7 @@ def __init__( self, script: Dict[str, Any], run_once: bool = False, + timeout: int = 10, **kwargs: Any, ): """Initialize a new script runner. @@ -29,11 +35,13 @@ def __init__( # store self.script = script self._script = self.add_child_object(script, Script) + self.timeout = timeout # add thread func if run_once: self.add_background_task(self._run_thread, False) + @timeout(calc_run_timeout) async def run(self, **kwargs: Any) -> None: """Run script.""" script = self.get_object(self.script, Script)