inoki-giskard commited on
Commit
92e2a79
1 Parent(s): 2c5cdf8

Use a flag to stop a thread because it cannot capture keyboard event

Browse files
Files changed (1) hide show
  1. run_jobs.py +10 -5
run_jobs.py CHANGED
@@ -1,16 +1,19 @@
1
  import threading
2
  import time
 
3
  import pipe
4
  from io_utils import pop_job_from_pipe
5
 
 
 
6
 
7
  def start_process_run_job():
8
  try:
9
  print("Running jobs in thread")
10
- global thread
11
  thread = threading.Thread(target=run_job)
12
  thread.daemon = True
13
- thread.do_run = True
14
  pipe.init()
15
  thread.start()
16
 
@@ -20,15 +23,17 @@ def start_process_run_job():
20
 
21
  def stop_thread():
22
  print("Stop thread")
23
- thread.do_run = False
 
24
 
25
 
26
  def run_job():
27
- while True:
 
28
  try:
29
  pop_job_from_pipe()
30
  time.sleep(10)
31
  except KeyboardInterrupt:
32
  print("KeyboardInterrupt stop background thread")
33
- stop_thread()
34
  break
 
1
  import threading
2
  import time
3
+
4
  import pipe
5
  from io_utils import pop_job_from_pipe
6
 
7
+ is_running = False
8
+
9
 
10
  def start_process_run_job():
11
  try:
12
  print("Running jobs in thread")
13
+ global thread, is_running
14
  thread = threading.Thread(target=run_job)
15
  thread.daemon = True
16
+ is_running = True
17
  pipe.init()
18
  thread.start()
19
 
 
23
 
24
  def stop_thread():
25
  print("Stop thread")
26
+ global is_running
27
+ is_running = False
28
 
29
 
30
  def run_job():
31
+ global is_running
32
+ while is_running:
33
  try:
34
  pop_job_from_pipe()
35
  time.sleep(10)
36
  except KeyboardInterrupt:
37
  print("KeyboardInterrupt stop background thread")
38
+ is_running = False
39
  break