Skip to content

Commit 074e03a

Browse files
authored
We do not need to account for drift when USE_WINDOWS_EVENTS
1 parent db177b3 commit 074e03a

File tree

1 file changed

+11
-12
lines changed

1 file changed

+11
-12
lines changed

can/broadcastmanager.py

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@
3535
log = logging.getLogger("can.bcm")
3636

3737
NANOSECONDS_IN_SECOND: Final[int] = 1_000_000_000
38-
NANOSECONDS_IN_MILLISECOND: Final[int] = 1_000_000
3938

4039

4140
class CyclicTask(abc.ABC):
@@ -316,19 +315,19 @@ def _run(self) -> None:
316315
self.stop()
317316
break
318317

319-
msg_due_time_ns += self.period_ns
318+
if not USE_WINDOWS_EVENTS:
319+
msg_due_time_ns += self.period_ns
320320
if self.end_time is not None and time.perf_counter() >= self.end_time:
321321
break
322322
msg_index = (msg_index + 1) % len(self.messages)
323323

324-
# Compensate for the time it takes to send the message
325-
delay_ns = msg_due_time_ns - time.perf_counter_ns()
326-
327-
if delay_ns > 0:
328-
if USE_WINDOWS_EVENTS:
329-
win32event.WaitForSingleObject(
330-
self.event.handle,
331-
int(round(delay_ns / NANOSECONDS_IN_MILLISECOND)),
332-
)
333-
else:
324+
if USE_WINDOWS_EVENTS:
325+
win32event.WaitForSingleObject(
326+
self.event.handle,
327+
-1,
328+
)
329+
else:
330+
# Compensate for the time it takes to send the message
331+
delay_ns = msg_due_time_ns - time.perf_counter_ns()
332+
if delay_ns > 0:
334333
time.sleep(delay_ns / NANOSECONDS_IN_SECOND)

0 commit comments

Comments
 (0)