@@ -175,6 +175,7 @@ def send_periodic(
175
175
msgs : Union [Sequence [Message ], Message ],
176
176
period : float ,
177
177
duration : Optional [float ] = None ,
178
+ count : Optional [int ] = None ,
178
179
store_task : bool = True ,
179
180
) -> can .broadcastmanager .CyclicSendTaskABC :
180
181
"""Start sending messages at a given period on this bus.
@@ -194,6 +195,9 @@ def send_periodic(
194
195
:param duration:
195
196
Approximate duration in seconds to continue sending messages. If
196
197
no duration is provided, the task will continue indefinitely.
198
+ :param count:
199
+ The number of messages to send before stopping. If
200
+ no count is provided, the task will continue indefinitely.
197
201
:param store_task:
198
202
If True (the default) the task will be attached to this Bus instance.
199
203
Disable to instead manage tasks manually.
@@ -222,7 +226,7 @@ def send_periodic(
222
226
raise ValueError ("Must be either a list, tuple, or a Message" )
223
227
if not msgs :
224
228
raise ValueError ("Must be at least a list or tuple of length 1" )
225
- task = self ._send_periodic_internal (msgs , period , duration )
229
+ task = self ._send_periodic_internal (msgs , period , duration , count )
226
230
# we wrap the task's stop method to also remove it from the Bus's list of tasks
227
231
original_stop_method = task .stop
228
232
@@ -246,6 +250,7 @@ def _send_periodic_internal(
246
250
msgs : Union [Sequence [Message ], Message ],
247
251
period : float ,
248
252
duration : Optional [float ] = None ,
253
+ count : Optional [int ] = None ,
249
254
) -> can .broadcastmanager .CyclicSendTaskABC :
250
255
"""Default implementation of periodic message sending using threading.
251
256
@@ -258,6 +263,9 @@ def _send_periodic_internal(
258
263
:param duration:
259
264
The duration between sending each message at the given rate. If
260
265
no duration is provided, the task will continue indefinitely.
266
+ :param count:
267
+ The number of messages to send before stopping. If
268
+ no count is provided, the task will continue indefinitely.
261
269
:return:
262
270
A started task instance. Note the task can be stopped (and
263
271
depending on the backend modified) by calling the :meth:`stop`
@@ -269,7 +277,7 @@ def _send_periodic_internal(
269
277
threading .Lock ()
270
278
) # pylint: disable=attribute-defined-outside-init
271
279
task = ThreadBasedCyclicSendTask (
272
- self , self ._lock_send_periodic , msgs , period , duration
280
+ self , self ._lock_send_periodic , msgs , period , duration , count
273
281
)
274
282
return task
275
283
0 commit comments