Skip to content

Commit 20d5520

Browse files
authored
Merge pull request #6 from mklomp/linetrace_fix
Adding extra check to make sure running process stops
2 parents 09342f0 + ccd290c commit 20d5520

1 file changed

Lines changed: 11 additions & 2 deletions

File tree

mirte_robot/linetrace.py

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,12 @@
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():
22+
global is_running
2123
process.terminate()
24+
is_running = False
2225

2326
def load_mirte_module(stepper, do_step):
2427

@@ -65,20 +68,26 @@ def traceit(frame, event, arg):
6568

6669
def start_mirte():
6770
global process
71+
# process should already have been killed after stop, or disconnect
72+
# but, just in case make sure to stop this
73+
if process.is_alive():
74+
process.terminate()
6875
process = multiprocessing.Process(target = load_mirte_module, args=(stepper, do_step))
6976
process.start()
7077

7178
def client_left(client, server):
7279
stop_mirte()
7380

7481
def message_received(client, server, message):
75-
global stepper, do_step
82+
global stepper, do_step, is_running
83+
7684
if message == "b": #break (pause)
7785
stepper.value = True
7886
if message == "c": #continue (play)
7987
stepper.value = False
80-
if not process.is_alive():
88+
if not is_running:
8189
start_mirte()
90+
is_running = True
8291
if message == "s": #step (step)
8392
do_step.value = True
8493
if message == "e": #exit (stop)

0 commit comments

Comments
 (0)