Skip to content

Commit 0a5b077

Browse files
author
Brendan Whitfield
committed
fixed bug where duplicate Async threads could be started
1 parent d664bd8 commit 0a5b077

1 file changed

Lines changed: 15 additions & 10 deletions

File tree

obd/async.py

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -51,17 +51,22 @@ def __init__(self, portstr=None, baudrate=38400):
5151

5252
def start(self):
5353
""" Starts the async update loop """
54-
if self.is_connected():
55-
if len(self.commands) > 0:
56-
debug("Starting async thread")
57-
self.running = True
58-
self.thread = threading.Thread(target=self.run)
59-
self.thread.daemon = True
60-
self.thread.start()
61-
else:
62-
debug("Async thread not started because no commands were registered")
63-
else:
54+
if not self.is_connected():
6455
debug("Async thread not started because no connection was made")
56+
return
57+
58+
if len(self.commands) == 0:
59+
debug("Async thread not started because no commands were registered")
60+
return
61+
62+
if self.thread is None:
63+
debug("Starting async thread")
64+
self.running = True
65+
self.thread = threading.Thread(target=self.run)
66+
self.thread.daemon = True
67+
self.thread.start()
68+
else:
69+
debug("Duplicate start(), async thread was already running")
6570

6671

6772
def stop(self):

0 commit comments

Comments
 (0)