Skip to content

Commit 53320ed

Browse files
authored
Implement per-driver lpp_timeout (#166)
* implement per-driver lpp_timeout * fix conftest v1
1 parent 64f2b42 commit 53320ed

4 files changed

Lines changed: 20 additions & 13 deletions

File tree

docs/source/driver_develop.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ When the *driver* process is launched (as a ``tomato-driver``), it's given infor
2121
The following keywords in the driver-specific settings in the |setfile|_ are reserved for use by **tomato**:
2222

2323
- ``idle_measurement_interval``: Specifies the interval (in seconds) after which the :func:`cmp_measure` function of all *components* registered on the *driver* should be called. The :func:`cmp_measure` checks that *components* are idle, i.e. without a running :class:`Task`. Overrides any :obj:`DriverInterface.idle_measurement_interval`.
24+
- ``lpp_timeout``: Specifies the timeout (in seconds) after which the communication with this *driver* interface will be retried. When unset, defaults to :obj:`tomato.daemon.lpp.REQ_TIMEOUT` (in milliseconds).
2425

2526

2627
Communication between *jobs* and *drivers*

src/tomato/daemon/job.py

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -506,10 +506,15 @@ def job_thread(
506506
endpoint=f"tcp://127.0.0.1:{driver.port}", context=context, sender=sender
507507
)
508508

509+
if "lpp_timeout" in driver.settings:
510+
lppargs["timeout"] = driver.settings["lpp_timeout"] * 1000
511+
logger.debug(
512+
"%s: setting lpp_timeout to %d ms", component.role, lppargs["timeout"]
513+
)
514+
509515
logger.info(
510516
"%s: job thread of %s attached to tomato-daemon", component.role, component.name
511517
)
512-
513518
kwargs = dict(address=component.address, channel=component.channel)
514519

515520
datapath = Path(jobpath) / f"{component.role}.pkl"
@@ -600,7 +605,7 @@ def job_thread(
600605
if tN - tP > device.pollrate:
601606
logger.debug("%s: polling task for data", taskid)
602607
msg = dict(cmd="task_data", params={**kwargs})
603-
ret, req = lpp.comm(req, msg, **lppargs, timeout=5000)
608+
ret, req = lpp.comm(req, msg, **lppargs) # , timeout=5000)
604609
if req.closed:
605610
thread.crashed = True
606611
sys.exit()
@@ -637,7 +642,7 @@ def job_thread(
637642
):
638643
logger.info("%s: task stop trigger met", taskid)
639644
msg = dict(cmd="task_stop", params={**kwargs})
640-
ret, req = lpp.comm(req, msg, **lppargs, timeout=5000)
645+
ret, req = lpp.comm(req, msg, **lppargs) # , timeout=5000)
641646
if req.closed:
642647
thread.crashed = True
643648
sys.exit()
@@ -653,7 +658,7 @@ def job_thread(
653658
# Store final task data, housekeeping.
654659
logger.info("%s: task fetching final data", taskid)
655660
msg = dict(cmd="task_data", params={**kwargs})
656-
ret, req = lpp.comm(req, msg, **lppargs, timeout=5000)
661+
ret, req = lpp.comm(req, msg, **lppargs) # , timeout=5000)
657662
if req.closed:
658663
thread.crashed = True
659664
sys.exit()
@@ -673,7 +678,7 @@ def job_thread(
673678
msg = dict(cmd="dev_reset", params={**kwargs})
674679
else:
675680
msg = dict(cmd="cmp_reset", params={**kwargs})
676-
ret, req = lpp.comm(req, msg, **lppargs, timeout=5000)
681+
ret, req = lpp.comm(req, msg, **lppargs) # , timeout=5000)
677682
if req.closed:
678683
thread.crashed = True
679684
sys.exit()

src/tomato/tomato/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -491,6 +491,7 @@ def init(
491491
492492
[drivers]
493493
example_counter.idle_measurement_interval = 1
494+
example_counter.lpp_timeout = 2
494495
"""
495496
)
496497
if not appdir.exists():

tests/conftest.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -60,12 +60,12 @@ def stop_tomato_daemon(port: int = 12345):
6060
for p in psutil.process_iter(["name"]):
6161
for name in ["tomato-daemon", "tomato-job", "tomato-driver"]:
6262
if name in p.info["name"]:
63-
pc = p.children()
64-
pc.append(p)
65-
for proc in pc:
66-
procs.append(proc)
67-
try:
68-
proc.terminate()
69-
except psutil.NoSuchProcess:
70-
pass
63+
try:
64+
pc = p.children()
65+
pc.append(p)
66+
for proc in pc:
67+
procs.append(proc)
68+
proc.terminate()
69+
except psutil.NoSuchProcess:
70+
pass
7171
gone, alive = psutil.wait_procs(procs, timeout=1)

0 commit comments

Comments
 (0)