Skip to content

Commit

Permalink
Fix usercode_runner crashing on successful completion of usercode
Browse files Browse the repository at this point in the history
  • Loading branch information
WillB97 committed Sep 1, 2024
1 parent be27d85 commit f93b2b3
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
3 changes: 2 additions & 1 deletion simulator/controllers/usercode_runner/usercode_runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -199,10 +199,11 @@ def main() -> bool:
# Run cleanup code registered in the usercode
atexit._run_exitfuncs() # noqa: SLF001
# Cleanup devices
devices.completed = True
devices.stop_event.set()

return True


if __name__ == '__main__':
exit(main())
exit(0 if main() else 1)
7 changes: 5 additions & 2 deletions simulator/modules/sbot_interface/socket_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,8 @@ def __init__(self, devices: list[DeviceServer]) -> None:
self.devices = devices
self.stop_event = Event()
g.stop_event = self.stop_event
# flag to indicate that we are exiting because the usercode has completed
self.completed = False

def run(self) -> None:
"""
Expand Down Expand Up @@ -199,8 +201,9 @@ def run(self) -> None:
for device in self.devices:
device.close()

# Stop the usercode
os.kill(os.getpid(), signal.SIGINT)
if self.stop_event.is_set() and self.completed is False:
# Stop the usercode
os.kill(os.getpid(), signal.SIGINT)

def links(self) -> dict[str, dict[str, str]]:
"""Return a mapping of asset tags to ports, grouped by board type."""
Expand Down

0 comments on commit f93b2b3

Please sign in to comment.