From 1532c6a38f3f165aeb8ba61c8748709fd2672cad Mon Sep 17 00:00:00 2001 From: Mike Stitt Date: Fri, 23 Jan 2026 12:47:35 -0500 Subject: [PATCH 1/2] Fix hang on exit for robotpy test and robotpy sim Signed-off-by: Mike Stitt --- src/pykit/loggedrobot.py | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/src/pykit/loggedrobot.py b/src/pykit/loggedrobot.py index f323978..85f383d 100644 --- a/src/pykit/loggedrobot.py +++ b/src/pykit/loggedrobot.py @@ -29,9 +29,19 @@ def __init__(self): """ IterativeRobotBase.__init__(self, LoggedRobot.default_period) self.useTiming = True - self._nextCycleUs = 0 + self._periodUs = int(self.getPeriod() * 1000000) + # Because in "robotpy test" this code starts at time 0 + # and hal.waitForNotifierAlarm returns (current_time_or_stopped, status) + # with current_time_or_stopped assigned to 0 when hal.stopNotifier is called + # or when the the current time is 0, and hal.stopNotifier is signal to + # exit the infinite loop, the stop is prematurely detected at time 0. + # Force the program to wait until self._periodUs for the first periodic loop + # so that current_time_or_stopped will contain a non-zero current time and the + # infinite loop does not end prematurely. + self._nextCycleUs = 0 + self._periodUs + self.notifier = hal.initializeNotifier()[0] self.watchdog = Watchdog(LoggedRobot.default_period, self.printOverrunMessage) self.word = DSControlWord() @@ -69,7 +79,9 @@ def startCompetition(self) -> None: self._nextCycleUs = currentTime else: hal.updateNotifierAlarm(self.notifier, int(self._nextCycleUs)) - if hal.waitForNotifierAlarm(self.notifier) == 0: + + currentTimeOrStopped, status = hal.waitForNotifierAlarm(self.notifier) + if currentTimeOrStopped == 0: break self._nextCycleUs += self._periodUs From 59edf20aa9a92299072b4a4ee2b8b97271add343 Mon Sep 17 00:00:00 2001 From: Luke Maxwell <91603936+lmaxwell24@users.noreply.github.com> Date: Fri, 23 Jan 2026 13:15:48 -0500 Subject: [PATCH 2/2] Formatting and status checking Exit upon unsuccessful notifier status, formatting --- src/pykit/loggedrobot.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/pykit/loggedrobot.py b/src/pykit/loggedrobot.py index 85f383d..5039f7a 100644 --- a/src/pykit/loggedrobot.py +++ b/src/pykit/loggedrobot.py @@ -80,7 +80,13 @@ def startCompetition(self) -> None: else: hal.updateNotifierAlarm(self.notifier, int(self._nextCycleUs)) - currentTimeOrStopped, status = hal.waitForNotifierAlarm(self.notifier) + currentTimeOrStopped, status = hal.waitForNotifierAlarm( + self.notifier + ) + if status != 0: + raise RuntimeError( + f"Error waiting for notifier alarm: status {status}" + ) if currentTimeOrStopped == 0: break self._nextCycleUs += self._periodUs