Skip to content

Commit 4033555

Browse files
committed
Restart exercise before load code
1 parent 28a136e commit 4033555

1 file changed

Lines changed: 19 additions & 1 deletion

File tree

manager/libs/applications/compatibility/exercise_wrapper.py

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@ def __init__(self, exercise_command, gui_command, update_callback):
2323
self.running = False
2424
self.linter = Lint()
2525
self.brain_ready_event = threading.Event()
26+
self.exercise_command = exercise_command
27+
self.gui_command = gui_command
28+
self.update_callback = update_callback
2629
# TODO: review hardcoded values
2730
process_ready, self.exercise_server = self._run_exercise_server(f"python {exercise_command}",
2831
f'{home_dir}/ws_code.log',
@@ -127,13 +130,28 @@ def pause(self):
127130
rosservice.call_service('/gazebo/pause_physics', [])
128131

129132
def restart(self):
130-
pass
133+
# Terminate current processes
134+
self.running= False
135+
home_dir = os.path.expanduser('~')
136+
stop_process_and_children(self.exercise_server)
137+
try:
138+
os.remove(f'{home_dir}/ws_code.log')
139+
except OSError as error:
140+
LogManager.logger.error(f"Error al eliminar el archivo log: {error}")
141+
142+
process_ready,self.exercise_server = self._run_exercise_server(f"python {self.exercise_command}",
143+
f'{home_dir}/ws_code.log',
144+
'websocket_code=ready')
145+
self.running= True
146+
131147

132148
@property
133149
def is_alive(self):
134150
return self.running
135151

136152
def load_code(self, code: str):
153+
self.restart()
154+
137155
errors = self.linter.evaluate_code(code)
138156
if errors == "":
139157
self.brain_ready_event.clear()

0 commit comments

Comments
 (0)