Skip to content

Commit d7f200b

Browse files
authored
Merge pull request #1245 from DominicOram/do_not_stop_ro_signals
Do not stop devices that cannot be stopped on Status failure
2 parents 496fae3 + 8bf17d0 commit d7f200b

File tree

2 files changed

+21
-2
lines changed

2 files changed

+21
-2
lines changed

ophyd/status.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -705,7 +705,8 @@ def __init__(self, device, **kwargs):
705705
def _handle_failure(self):
706706
super()._handle_failure()
707707
self.log.debug("Trying to stop %s", repr(self.device))
708-
self.device.stop()
708+
if hasattr(self.device, "stop"):
709+
self.device.stop()
709710

710711
def __str__(self):
711712
device_name = self.device.name if self.device else "None"

ophyd/tests/test_status.py

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
import time
2-
from unittest.mock import Mock
2+
from unittest.mock import MagicMock, Mock
33

44
import pytest
55

66
from ophyd import Device
7+
from ophyd.signal import EpicsSignalRO
78
from ophyd.status import (
89
MoveStatus,
910
StableSubscriptionStatus,
@@ -142,6 +143,23 @@ def cb(*args, done=False, **kwargs):
142143
assert status.done and status.success
143144

144145

146+
def test_subscription_status_does_not_try_and_stop_ro_device():
147+
# Arbitrary device
148+
d = EpicsSignalRO("Tst:Prefix", name="test")
149+
150+
# Full fake callback signature
151+
def cb(*args, **kwargs):
152+
pass
153+
154+
status = SubscriptionStatus(d, cb, event_type=d.SUB_VALUE)
155+
status._settled_event.set()
156+
status.set_exception(Exception())
157+
status.log.exception = MagicMock()
158+
159+
status._run_callbacks()
160+
status.log.exception.assert_not_called()
161+
162+
145163
def test_given_stability_time_greater_than_timeout_then_exception_on_initialisation():
146164
# Arbitrary device
147165
d = Device("Tst:Prefix", name="test")

0 commit comments

Comments
 (0)