Skip to content

Commit a353324

Browse files
committed
Running also stops when process finishes
1 parent e4e3a36 commit a353324

1 file changed

Lines changed: 17 additions & 10 deletions

File tree

mirte_robot/linetrace.py

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,19 @@
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
19+
running = multiprocessing.Value('b', False)
2020

21-
def stop_mirte():
22-
global is_running
23-
process.terminate()
24-
is_running = False
21+
# the stop be stopped when:
22+
# 1) the code finishes
23+
# 2) the user stopped the process
24+
# 3) the websocket connection is closed
25+
def stop_mirte(terminate = True):
26+
global running
27+
if terminate:
28+
process.terminate()
29+
running.value = False
2530

26-
def load_mirte_module(stepper, do_step):
31+
def load_mirte_module(stepper, do_step, running):
2732

2833
def trace_lines(frame, event, arg):
2934
global do_step
@@ -64,6 +69,8 @@ def traceit(frame, event, arg):
6469
# Sending the linetrace 0 to the client
6570
server.send_message_to_all("0")
6671

72+
stop_mirte(False)
73+
6774
process = multiprocessing.Process(target = load_mirte_module, args=(stepper, do_step))
6875

6976
def start_mirte():
@@ -72,22 +79,22 @@ def start_mirte():
7279
# but, just in case make sure to stop this
7380
if process.is_alive():
7481
process.terminate()
75-
process = multiprocessing.Process(target = load_mirte_module, args=(stepper, do_step))
82+
process = multiprocessing.Process(target = load_mirte_module, args=(stepper, do_step, running))
7683
process.start()
7784

7885
def client_left(client, server):
7986
stop_mirte()
8087

8188
def message_received(client, server, message):
82-
global stepper, do_step, is_running
89+
global stepper, do_step, running
8390

8491
if message == "b": #break (pause)
8592
stepper.value = True
8693
if message == "c": #continue (play)
8794
stepper.value = False
88-
if not is_running:
95+
if not running.value:
8996
start_mirte()
90-
is_running = True
97+
running.value = True
9198
if message == "s": #step (step)
9299
do_step.value = True
93100
if message == "e": #exit (stop)

0 commit comments

Comments
 (0)