diff --git a/artiq/language/core.py b/artiq/language/core.py index ec7d739ac..4d73f324e 100644 --- a/artiq/language/core.py +++ b/artiq/language/core.py @@ -1,6 +1,5 @@ """ Core ARTIQ extensions to the Python language. - """ from collections import namedtuple as _namedtuple @@ -170,14 +169,12 @@ def set_syscall_manager(syscall_manager): kernel_globals = ("sequential", "parallel", "delay", "now", "at", "time_to_cycles", "cycles_to_time", - "syscall") + "syscall", "watchdog") class _Sequential: """In a sequential block, statements are executed one after another, with - the time increasing as one moves down the statement list. - - """ + the time increasing as one moves down the statement list.""" def __enter__(self): _time_manager.enter_sequential() @@ -243,7 +240,6 @@ def cycles_to_time(cycles, core=None): :param time: Cycle count to convert. :param core: Core device for which to perform the conversion. Specify only when running in the interpreter (not in kernel). - """ if core is None: raise ValueError("Core device must be specified for time conversion") @@ -257,19 +253,40 @@ def syscall(*args): events, make RPCs, etc. Only drivers should normally use ``syscall``. - """ return _syscall_manager.do(*args) +class _DummyWatchdog: + def __init__(self, timeout): + pass + + def __enter__(self): + pass + + def __exit__(self, type, value, traceback): + pass + + +# Watchdogs are simply not enforced by default. +_watchdog_factory = _DummyWatchdog + + +def set_watchdog_factory(f): + global _watchdog_factory + _watchdog_factory = f + + +def watchdog(timeout): + return _watchdog_factory(timeout) + + _encoded_exceptions = dict() def EncodedException(eid): """Represents exceptions on the core device, which are identified - by a single number. - - """ + by a single number.""" try: return _encoded_exceptions[eid] except KeyError: diff --git a/artiq/master/worker_impl.py b/artiq/master/worker_impl.py index c4fc6ccf8..361af948e 100644 --- a/artiq/master/worker_impl.py +++ b/artiq/master/worker_impl.py @@ -6,6 +6,7 @@ from artiq.tools import file_import from artiq.master.worker_db import DBHub, ResultDB from artiq.master.results import get_hdf5_output from artiq.language.experiment import is_experiment +from artiq.language.core import set_watchdog_factory def get_object(): @@ -66,13 +67,15 @@ class Watchdog: Watchdog._delete(self.wid) +set_watchdog_factory(Watchdog) + + class Scheduler: run_queued = make_parent_action("scheduler_run_queued", "run_params") cancel_queued = make_parent_action("scheduler_cancel_queued", "rid") run_timed = make_parent_action("scheduler_run_timed", "run_params next_run") cancel_timed = make_parent_action("scheduler_cancel_timed", "trid") - watchdog = Watchdog def get_exp(file, exp): diff --git a/artiq/test/worker.py b/artiq/test/worker.py index 80e76735a..7c01b8b1c 100644 --- a/artiq/test/worker.py +++ b/artiq/test/worker.py @@ -10,19 +10,19 @@ from artiq.master.worker import * class WatchdogNoTimeout(Experiment, AutoDB): def run(self): for i in range(10): - with self.scheduler.watchdog(0.5*s): + with watchdog(0.5*s): sleep(0.1) class WatchdogTimeout(Experiment, AutoDB): def run(self): - with self.scheduler.watchdog(0.1*s): + with watchdog(0.1*s): sleep(100.0) class WatchdogTimeoutInBuild(Experiment, AutoDB): def build(self): - with self.scheduler.watchdog(0.1*s): + with watchdog(0.1*s): sleep(100.0) def run(self):