Skip to content

Commit

Permalink
Merge pull request #702 from lnls-sirius/pssofb-wait-timeout
Browse files Browse the repository at this point in the history
SOFB.MNT: remove debug events in PSSOFB.
  • Loading branch information
anacso17 authored Jun 21, 2021
2 parents 671a22f + dad0d4c commit c328990
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 33 deletions.
25 changes: 5 additions & 20 deletions siriuspy/siriuspy/pwrsupply/pssofb.py
Original file line number Diff line number Diff line change
Expand Up @@ -703,7 +703,6 @@ def __init__(self, ethbridgeclnt_class, nr_procs=8, asynchronous=False,
self._ethbridge_cls = ethbridgeclnt_class
self._nr_procs = nr_procs
self._doneevts = []
self._recevts = []
self._procs = []
self._pipes = []

Expand All @@ -720,23 +719,15 @@ def asynchronous(self, val):

def wait(self, timeout=None):
"""."""
for i, (doneevt, recevt) in enumerate(zip(
self._doneevts, self._recevts)):
if not recevt.wait(timeout=timeout):
_log.error('Wait Receive timed out for process '+str(i))
return None
for i, doneevt in enumerate(self._doneevts):
if not doneevt.wait(timeout=timeout):
_log.error('Wait Done timed out for process '+str(i))
return False
return True

def is_ready(self):
"""."""
for i, (doneevt, recevt) in enumerate(zip(
self._doneevts, self._recevts)):
if not recevt.is_set():
_log.error('Ready: not received for process '+str(i))
return None
for i, doneevt in enumerate(self._doneevts):
if not doneevt.is_set():
_log.error('Ready: not done for process '+str(i))
return False
Expand Down Expand Up @@ -777,19 +768,16 @@ def processes_start(self):
# NOTE: It is crucial to use the Event class from the appropriate
# context, otherwise it will fail for 'spawn' start method.
doneevt = spw.Event()
recevt = spw.Event()
doneevt.set()
recevt.set()
theirs, mine = spw.Pipe(duplex=False)
proc = _Process(
target=PSSOFB._run_process,
args=(self._ethbridge_cls, bbbnames, theirs, doneevt, recevt,
args=(self._ethbridge_cls, bbbnames, theirs, doneevt,
arr.shape, rbref, ref, fret, self._sofb_update_iocs),
daemon=True)
proc.start()
self._procs.append(proc)
self._doneevts.append(doneevt)
self._recevts.append(recevt)
self._pipes.append(mine)

def processes_shutdown(self):
Expand Down Expand Up @@ -892,7 +880,7 @@ def sofb_conv_psname_2_index(self, psname):

@staticmethod
def _run_process(
ethbridgeclnt_class, bbbnames, pipe, doneevt, recevt,
ethbridgeclnt_class, bbbnames, pipe, doneevt,
shape, rbref, ref, fret, sofb_update_iocs):
"""."""
mproc = {
Expand All @@ -909,7 +897,6 @@ def _run_process(
rec = pipe.recv()
if not rec:
break
recevt.set()
meth, args = rec
if isinstance(meth, str):
if isinstance(args, Iterable):
Expand All @@ -924,10 +911,8 @@ def _run_process(

def _parallel_execution(self, target_name, args=None):
"""Execute 'method' in parallel."""
for pipe, doneevt, recevt in zip(
self._pipes, self._doneevts, self._recevts):
for pipe, doneevt in zip(self._pipes, self._doneevts):
doneevt.clear()
recevt.clear()
pipe.send((target_name, args))

if not self._async:
Expand Down
14 changes: 4 additions & 10 deletions siriuspy/siriuspy/sofb/correctors.py
Original file line number Diff line number Diff line change
Expand Up @@ -578,16 +578,10 @@ def apply_kicks_pssofb(self, values):
if not _np.isnan(values[-1]):
self.put_value_in_corr(self._corrs[-1], values[-1])

if self._wait_pssofb:
ret = self._pssofb.wait(timeout=1)
if ret is None:
msg = 'ERR: PSSOFB timed out: Worker did not Receive!'
self._update_log(msg)
_log.error(msg[5:])
elif ret is False:
msg = 'ERR: PSSOFB timed out: Worker is not Done!'
self._update_log(msg)
_log.error(msg[5:])
if self._wait_pssofb and not self._pssofb.wait(timeout=1):
msg = 'ERR: PSSOFB timed out: Worker is not Done!'
self._update_log(msg)
_log.error(msg[5:])

# compare kicks to check if there is something wrong
ret = self._compare_kicks_pssofb(ret_kicks, func_ret)
Expand Down
4 changes: 1 addition & 3 deletions siriuspy/siriuspy/thread.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,8 @@ def configure_new_run(self, target, args=None):
self.target = target
self.args = args or tuple()
self._evt_ready.clear()
# NOTE: _evt_received setting must be last operation of this method.
self._evt_received.set()
# NOTE: clearing evt_ready after seting evt_received may create
# hanging problems with a very low error rate:
# self._evt_ready.clear()
return True

def wait_ready(self, timeout=None):
Expand Down

0 comments on commit c328990

Please sign in to comment.