@@ -25,13 +25,12 @@ def __init__(self, messages, modulators, num_repeats=-1):
25
25
self .modulators = modulators
26
26
self .num_repeats = num_repeats # -1 or 0 = infinite
27
27
28
- self .ring_buffer = RingBuffer (int (settings .CONTINUOUS_BUFFER_SIZE_MB * 10 ** 6 ) // 8 , dtype = Modulator .get_dtype ())
28
+ self .ring_buffer = RingBuffer (int (settings .CONTINUOUS_BUFFER_SIZE_MB * 1e6 ) // 8 , dtype = Modulator .get_dtype ())
29
29
30
30
self .current_message_index = Value ("L" , 0 )
31
31
32
32
self .abort = Value ("i" , 0 )
33
- self .process = Process (target = self .modulate_continuously , args = (self .num_repeats , ))
34
- self .process .daemon = True
33
+ self .process = Process (target = self .modulate_continuously , args = (self .num_repeats , ), daemon = True )
35
34
36
35
@property
37
36
def is_running (self ):
@@ -40,34 +39,34 @@ def is_running(self):
40
39
def start (self ):
41
40
self .abort .value = 0
42
41
try :
43
- self .process = Process (target = self .modulate_continuously , args = (self .num_repeats , ))
44
- self .process .daemon = True
42
+ self .process = Process (target = self .modulate_continuously , args = (self .num_repeats , ), daemon = True )
45
43
self .process .start ()
46
44
except RuntimeError as e :
47
- logger .debug ( str ( e ) )
45
+ logger .exception ( e )
48
46
49
47
def stop (self , clear_buffer = True ):
50
48
self .abort .value = 1
51
- if clear_buffer :
52
- self .ring_buffer .clear ()
53
- if not self .process .is_alive ():
54
- return
55
-
56
- try :
57
- self .process .join (0.1 )
58
- except RuntimeError as e :
59
- logger .debug (str (e ))
60
49
61
50
if self .process .is_alive ():
62
- self .process .terminate ()
63
- self .process .join ()
51
+ try :
52
+ self .process .join (1.5 )
53
+ except RuntimeError as e :
54
+ logger .exception (e )
55
+ self .process .terminate ()
56
+
57
+ if clear_buffer :
58
+ self .ring_buffer .clear ()
64
59
65
60
logger .debug ("Stopped continuous modulation" )
66
61
67
62
def modulate_continuously (self , num_repeats ):
68
63
rng = iter (int , 1 ) if num_repeats <= 0 else range (0 , num_repeats ) # <= 0 = forever
69
64
for _ in rng :
65
+ if self .abort .value :
66
+ return
67
+
70
68
start = self .current_message_index .value
69
+
71
70
for i in range (start , len (self .messages )):
72
71
if self .abort .value :
73
72
return
@@ -82,5 +81,7 @@ def modulate_continuously(self, num_repeats):
82
81
83
82
# Wait till there is space in buffer
84
83
time .sleep (self .WAIT_TIMEOUT )
84
+
85
85
self .ring_buffer .push (modulated )
86
+
86
87
self .current_message_index .value = 0
0 commit comments