-
Notifications
You must be signed in to change notification settings - Fork 377
Async Querying
Since the standard query()
function is blocking, it can be a hazard for UI event loops. To deal with this, python-OBD has an Async
connection object that can be used in place of the standard OBD
object.
import obd
connection = obd.Async() # same constructor as 'obd.OBD()'
connection.watch(obd.commands.RPM) # tell python-OBD to keep track of the RPM
print connection.query(obd.commands.RPM) # non-blocking, returns immediately
Async
is a subclass of OBD
, and therefore inherits all of the standard methods. However, Async
adds a few, in order to manage a list of sensors (commands) being watched. It works by maintaining a list of commands, and keeping their Response
s up-to-date. This way, when the user query
s the car, the latest response is returned immediately.
The watch()
method subscribes a command to be continuously updated. After calling watch()
, the query()
function will return the latest Response
from that command. An optional force
parameter will force an unsupported command to be sent.
Unsubscribes a command from being updated.