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