Skip to content

Commit

Permalink
timeout for run() method can be defined in config
Browse files Browse the repository at this point in the history
  • Loading branch information
thusser committed Dec 26, 2023
1 parent a1bdc74 commit 7f3c2d9
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion pyobs/modules/robotic/scriptrunner.py
Original file line number Diff line number Diff line change
@@ -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."""

Expand All @@ -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.
Expand All @@ -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)
Expand Down

0 comments on commit 7f3c2d9

Please sign in to comment.