Skip to content

Commit bbbbaa7

Browse files
author
Vincent Michel
committed
Add Action.interrupted property
1 parent 4160f63 commit bbbbaa7

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

sequence/action/abstract.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -255,12 +255,17 @@ def set_default_parameters(cls, params):
255255
raise ActionCreationError(msg)
256256
setattr(cls, name, value)
257257

258+
@property
259+
def interrupted(self):
260+
return self._stop_thread and self._stop_thread.is_set()
261+
258262
def __init__(self, name, module, iteration, tick, parameters):
259263
"""
260264
Initialize action
261265
"""
262266
# Set properties
263267
self._log_dict = None
268+
self._stop_thread = None
264269
self._name = name
265270
self._module = module
266271
self._iteration = iteration
@@ -294,7 +299,7 @@ def execute(self, stop_thread, log_dict):
294299
if not self._valid_pre_run_flag:
295300
self.warning('PreRun returned False')
296301
# Stop thread activated case
297-
elif self._stop_thread.is_set():
302+
elif self.interrupted:
298303
self.warning('The stop mecanism has been activated during PreRun')
299304
# If PreRun returned True
300305
elif self._valid_pre_run_flag:
@@ -318,7 +323,7 @@ def execute(self, stop_thread, log_dict):
318323
self.warning(msg)
319324
break
320325
# Break if stop thread activated
321-
if self._stop_thread.is_set() and i != self._iteration-1:
326+
if self.interrupted and i != self._iteration-1:
322327
msg = 'The stop mecanism has been activated during Run'
323328
msg += ' (execution {})'.format(i+1)
324329
self.warning(msg)
@@ -327,7 +332,7 @@ def execute(self, stop_thread, log_dict):
327332
self._valid_run_count += 1
328333
sleep(self._tick)
329334
# Break if stop thread activated
330-
if self._stop_thread.is_set() and i != self._iteration-1:
335+
if self.interrupted and i != self._iteration-1:
331336
msg = 'The stop mecanism has been activated during Run'
332337
msg += ' (tick {})'.format(i+1)
333338
self.warning(msg)

0 commit comments

Comments
 (0)