From 46adc9cdedcb4181870dec693fa4365ec47461be Mon Sep 17 00:00:00 2001 From: WillB97 Date: Sun, 18 Aug 2024 11:46:45 +0100 Subject: [PATCH] Make usercode terminate properly when resetting the world --- simulator/modules/sbot_interface/socket_server.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/simulator/modules/sbot_interface/socket_server.py b/simulator/modules/sbot_interface/socket_server.py index 4beb23e..a51c7d0 100644 --- a/simulator/modules/sbot_interface/socket_server.py +++ b/simulator/modules/sbot_interface/socket_server.py @@ -2,7 +2,9 @@ from __future__ import annotations import logging +import os import select +import signal import socket import sys from threading import Event @@ -193,6 +195,13 @@ def run(self) -> None: except Exception as e: LOGGER.exception(f"Failure in simulated boards: {e}") + LOGGER.info('Stopping server') + for device in self.devices: + device.close() + + # 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.""" return {