Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

using async without a thread #110

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions obd/async.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,30 @@ def running(self):
return self.__running


def main_loop(self):
""" Starts the async update loop without using thread """
if not self.is_connected():
logger.info("Async thread not started because no connection was made")
return

if len(self.__commands) == 0:
logger.info("Async thread not started because no commands were registered")
return

if self.__thread is None:
logger.info("Starting async thread")
self.__running = True
try:
self.__thread = Async.main_loop
self.run()
except Exception as e:
logger.info('Exception %s' % str(e))
if self.__thread is not None:
assert self.__thread == Async.main_loop
self.__running = False
self.__thread = None


def start(self):
""" Starts the async update loop """
if not self.is_connected():
Expand Down