Skip to content

Commit b364630

Browse files
committed
fix: thread must be singleton
1 parent aa24aca commit b364630

File tree

2 files changed

+10
-6
lines changed

2 files changed

+10
-6
lines changed

arduino_alvik.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313

1414
class ArduinoAlvik:
1515

16+
_update_thread_running = False
17+
1618
def __init__(self):
1719
self.packeter = ucPack(200)
1820
self.left_wheel = _ArduinoAlvikWheel(self.packeter, ord('L'))
@@ -64,15 +66,17 @@ def _begin_update_thread(self):
6466
Runs robot background operations (e.g. threaded update)
6567
:return:
6668
"""
67-
self._update_thread_running = True
68-
self._update_thread_id = _thread.start_new_thread(self._update, (1,))
69+
70+
if not ArduinoAlvik._update_thread_running:
71+
ArduinoAlvik._update_thread_running = True
72+
self._update_thread_id = _thread.start_new_thread(self._update, (1,))
6973

7074
def _stop_update_thread(self):
7175
"""
7276
Stops the background operations
7377
:return:
7478
"""
75-
self._update_thread_running = False
79+
ArduinoAlvik._update_thread_running = False
7680

7781
def stop(self):
7882
"""
@@ -220,7 +224,7 @@ def _update(self, delay_=1):
220224
:return:
221225
"""
222226
while True:
223-
if not self._update_thread_running:
227+
if not ArduinoAlvik._update_thread_running:
224228
break
225229
if self._read_message():
226230
self._parse_message()

examples/message_reader.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,5 +23,5 @@
2323
except KeyboardInterrupt as e:
2424
print('over')
2525
alvik.stop()
26-
break
27-
sys.exit()
26+
sys.exit()
27+

0 commit comments

Comments
 (0)