Skip to content

Commit

Permalink
resolving noted issues
Browse files Browse the repository at this point in the history
  • Loading branch information
awalter-bnl committed Oct 26, 2018
1 parent d1da6a2 commit 9fe51f8
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 8 deletions.
16 changes: 10 additions & 6 deletions nslsii/temperature_controllers.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from ophyd import DeviceStatus, Device, Component as Cpt, EpicsSignal, Signal
import threading as th
import threading


class Eurotherm(Device):
Expand All @@ -22,8 +22,7 @@ class Eurotherm(Device):

def __init__(self, pv_prefix, **kwargs):
super().__init__(pv_prefix, **kwargs)
self._set_lock = th.Lock()
self._cid = None
self._set_lock = threading.Lock()

# Setup some new signals required for the moving indicator logic
equilibrium_time = Cpt(Signal, value=5)
Expand All @@ -38,8 +37,8 @@ def __init__(self, pv_prefix, **kwargs):
def set(self, value):
# check that a set is not in progress, and if not set the lock.
if not self._set_lock.acquire(blocking=False):
raise Exception('attempting to set {} '.format(self.name) +
'while a set is in progress'.format(self.name))
raise SetInProgress('attempting to set {} '.format(self.name) +
'while a set is in progress')

# define some required values
set_value = value
Expand All @@ -60,7 +59,8 @@ def timer_cleanup(status):
self.readback.clear_sub(status_indicator)
status._finished(success=False)

cb_timer = th.Timer(self.timeout.get(), timer_cleanup, args=[status])
cb_timer = threading.Timer(self.timeout.get(), timer_cleanup,
args=(status,))

# set up the done moving indicator logic
def status_indicator(value, timestamp, **kwargs):
Expand Down Expand Up @@ -95,3 +95,7 @@ def stop(self):
self._set_lock.release()
# set the controller to the current value (best option we came up with)
self.set(self.readback.get())


class SetInProgress(RuntimeError):
...
4 changes: 2 additions & 2 deletions nslsii/tests/temperature_controllers_test.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from nslsii.temperature_controllers import Eurotherm
from nslsii.temperature_controllers import Eurotherm, SetInProgress
from bluesky.plan_stubs import mv
from bluesky import RunEngine
from bluesky.utils import FailedStatus
Expand Down Expand Up @@ -55,7 +55,7 @@ def test_Eurotherm(RE):
euro.timeout.set(500) # reset to default for the following tests.

# test that the lock prevents setting while set in progress
with pytest.raises(Exception):
with pytest.raises(SetInProgress):
for i in range(2): # The previous set may or may not be complete
euro.set(100)

Expand Down

0 comments on commit 9fe51f8

Please sign in to comment.