mirror of
https://github.com/m-labs/artiq.git
synced 2024-12-28 20:53:35 +08:00
language/core: integrate watchdogs
This commit is contained in:
parent
37ac6c4542
commit
283695e8aa
@ -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:
|
||||
|
@ -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):
|
||||
|
@ -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):
|
||||
|
Loading…
Reference in New Issue
Block a user