Allow RestartableCyclicTaskABC using Windows events to restart by pierreluctg · Pull Request #1679 · hardbyte/python-can

@pierreluctg

Allow RestartableCyclicTaskABC using Windows events to restart

Also adding unit test to cover RestartableCyclicTaskABC and avoid this type of bug.

@pierreluctg

@zariiii9003 please review and consider for a bug fix release.

zariiii9003

@zariiii9003

Semi-related: Could you check why the SimpleCyclicSendTaskTest test is so slow after #1666?
I assume win32event.INFINITE might be a problem, when the timer gets cancelled. Maybe we could just set a multiple of the requested cycle time as the timeout.

Second edit: The win32event.INFINITE is the reason why self.thread.is_alive() returns True when you try to restart.

@pierreluctg

SimpleCyclicSendTaskTest

You are right, will fix it

Also adding unit test to cover RestartableCyclicTaskABC

@pierreluctg

@zariiii9003 please have another look. This should address the issues.

The CancelWaitableTimer function does not change the signaled state of the timer.

So the thread was waiting for ever (win32event.INFINITE) on the cancled event.
This change replace CancelWaitableTimer by SetWaitableTimer with a period of 0.

This is documented in the SetWaitableTimer API doc.

A periodic timer automatically reactivates each time the period elapses, until the timer is canceled using the CancelWaitableTimer function or reset using SetWaitableTimer.

zariiii9003

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good. The reset with SetWaitableTimer is a nice solution.

@mergify mergify bot deleted the bcm-win-event-resume-bug branch

October 16, 2023 19:48