Skip to content

Commit f93b2b3

Browse files
committed
Fix usercode_runner crashing on successful completion of usercode
1 parent be27d85 commit f93b2b3

File tree

2 files changed

+7
-3
lines changed

2 files changed

+7
-3
lines changed

simulator/controllers/usercode_runner/usercode_runner.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -199,10 +199,11 @@ def main() -> bool:
199199
# Run cleanup code registered in the usercode
200200
atexit._run_exitfuncs() # noqa: SLF001
201201
# Cleanup devices
202+
devices.completed = True
202203
devices.stop_event.set()
203204

204205
return True
205206

206207

207208
if __name__ == '__main__':
208-
exit(main())
209+
exit(0 if main() else 1)

simulator/modules/sbot_interface/socket_server.py

+5-2
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,8 @@ def __init__(self, devices: list[DeviceServer]) -> None:
154154
self.devices = devices
155155
self.stop_event = Event()
156156
g.stop_event = self.stop_event
157+
# flag to indicate that we are exiting because the usercode has completed
158+
self.completed = False
157159

158160
def run(self) -> None:
159161
"""
@@ -199,8 +201,9 @@ def run(self) -> None:
199201
for device in self.devices:
200202
device.close()
201203

202-
# Stop the usercode
203-
os.kill(os.getpid(), signal.SIGINT)
204+
if self.stop_event.is_set() and self.completed is False:
205+
# Stop the usercode
206+
os.kill(os.getpid(), signal.SIGINT)
204207

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

0 commit comments

Comments
 (0)