@@ -198,10 +198,7 @@ def send_periodic(self, msg, period, duration=None, store_task=True):
198198 api with ``store_task==True`` may not be appropriate as the stopped tasks are
199199 still taking up memory as they are associated with the Bus instance.
200200 """
201- if not hasattr (self , "_lock_send_periodic" ):
202- # Create a send lock for this bus
203- self ._lock_send_periodic = threading .Lock ()
204- task = ThreadBasedCyclicSendTask (self , self ._lock_send_periodic , msg , period , duration )
201+ task = self ._send_periodic_internal (msg , period , duration )
205202 # we wrap the task's stop method to also remove it from the Bus's list of tasks
206203 original_stop_method = task .stop
207204
@@ -213,8 +210,33 @@ def wrapped_stop_method(remove_task=True):
213210 pass
214211 original_stop_method ()
215212 task .stop = wrapped_stop_method
213+
216214 if store_task :
217215 self ._periodic_tasks .append (task )
216+
217+ return task
218+
219+ def _send_periodic_internal (self , msg , period , duration = None ):
220+ """Default implementation of periodic message sending using threading.
221+
222+ Override this method to enable a more efficient backend specific approach.
223+
224+ :param can.Message msg:
225+ Message to transmit
226+ :param float period:
227+ Period in seconds between each message
228+ :param float duration:
229+ The duration to keep sending this message at given rate. If
230+ no duration is provided, the task will continue indefinitely.
231+ :return:
232+ A started task instance. Note the task can be stopped (and depending on
233+ the backend modified) by calling the :meth:`stop` method.
234+ :rtype: can.broadcastmanager.CyclicSendTaskABC
235+ """
236+ if not hasattr (self , "_lock_send_periodic" ):
237+ # Create a send lock for this bus
238+ self ._lock_send_periodic = threading .Lock ()
239+ task = ThreadBasedCyclicSendTask (self , self ._lock_send_periodic , msg , period , duration )
218240 return task
219241
220242 def stop_all_periodic_tasks (self , remove_tasks = True ):
0 commit comments