hardbyte / python-can

The can package provides controller area network support for Python developers
https://python-can.readthedocs.io
GNU Lesser General Public License v3.0
1.31k stars 604 forks source link

ThreadBasedCyclicSendTask won't start again #1866

Closed phettberg closed 1 month ago

phettberg commented 1 month ago

Describe the bug

When instantiating ThreadBasedCyclicSendTask by calling bus.send_periodic, with a certain duration, the task won't start again after calling .start

The problem is, that self.end_time is only set at init in broadcastmanager.py

 self.end_time: Optional[float] = (
     time.perf_counter() + duration if duration else None
 )

Then it only works the first time when the thread is started immediately

 while not self.stopped:
     if self.end_time is not None and time.perf_counter() >= self.end_time:
         break

However, it should be set again, either in .start() or in _run().

I guess this might affect #1848 #1853 as well.

To Reproduce

Expected behavior

The defined periodic task should start again, with the same duration and interval.

Additional context

OS and version: Ubuntu 24.04.1 LTS Python version: 3.12.3 python-can version: 4.4.2 python-can interface/s (if applicable): socketcan and IXXAT

Traceback and logs