Skip to content

Commit a5562e4

Browse files
committed
Adding extra check to make sure running process stops
1 parent 09342f0 commit a5562e4

1 file changed

Lines changed: 10 additions & 2 deletions

File tree

mirte_robot/linetrace.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
# Global shared memory objects (TODO: check if we need shared memory, why is server working?)
1717
stepper = multiprocessing.Value('b', True)
1818
do_step = multiprocessing.Value('b', False)
19+
is_running = False
1920

2021
def stop_mirte():
2122
process.terminate()
@@ -65,25 +66,32 @@ def traceit(frame, event, arg):
6566

6667
def start_mirte():
6768
global process
69+
# process should already have been killed after stop, or disconnect
70+
# but, just in case make sure to stop this
71+
if process.is_alive():
72+
process.terminate()
6873
process = multiprocessing.Process(target = load_mirte_module, args=(stepper, do_step))
6974
process.start()
7075

7176
def client_left(client, server):
7277
stop_mirte()
7378

7479
def message_received(client, server, message):
75-
global stepper, do_step
80+
global stepper, do_step, is_running
81+
7682
if message == "b": #break (pause)
7783
stepper.value = True
7884
if message == "c": #continue (play)
7985
stepper.value = False
80-
if not process.is_alive():
86+
if not is_running:
8187
start_mirte()
88+
is_running = True
8289
if message == "s": #step (step)
8390
do_step.value = True
8491
if message == "e": #exit (stop)
8592
stepper.value = True
8693
do_step.value = False
94+
is_running = False
8795
stop_mirte()
8896

8997
server = WebsocketServer(host="0.0.0.0", port=8001, loglevel=logging.CRITICAL)

0 commit comments

Comments
 (0)