Skip to content

Commit f964e64

Browse files
committed
Fix usercode_runner crashing on successful completion of usercode
1 parent 46adc9c commit f964e64

File tree

2 files changed

+7
-3
lines changed

2 files changed

+7
-3
lines changed

simulator/controllers/usercode_runner/usercode_runner.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -197,10 +197,11 @@ def main() -> bool:
197197
# Run cleanup code registered in the usercode
198198
atexit._run_exitfuncs() # noqa: SLF001
199199
# Cleanup devices
200+
devices.completed = True
200201
devices.stop_event.set()
201202

202203
return True
203204

204205

205206
if __name__ == '__main__':
206-
exit(main())
207+
exit(0 if main() else 1)

simulator/modules/sbot_interface/socket_server.py

Lines changed: 5 additions & 2 deletions
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)