Interface Locking¶
The interfaces in this chapter are used to lock all API interfaces, allowing you to restrict interfaces to only be used by the current Device instance. This prevents the API from being used by other users or processes. You can set a default lock duration or periodically refresh the lock yourself. The periodic refresh method is recommended. You can also actively release the interface lock. A secure locking process is: Acquire lock -> Create a thread to periodically refresh the lock -> Release the lock.
Acquire Lock¶
Acquire a lock. This lock will be automatically released after 60 seconds. After automatic release, other clients will be able to acquire the lock. You can change this time, but if you set it too high, due to abnormal script exits, you will almost never be able to connect to the device again, and you may need to restart to continue connecting. This interface is reentrant; when reentered, it is equivalent to _refresh_lock.
d._acquire_lock(leaseTime=60)
Release Lock¶
Actively release the API lock, after which other clients will be able to acquire the lock.
d._release_lock()
Refresh Lock¶
Refresh the lock. Each call sets the lock expiration time to this leaseTime. Make periodic calls to this interface to maintain the API lock. Similarly, if the leaseTime is too high, due to abnormal script exits, you will almost never be able to connect to the device again.
d._refresh_lock(leaseTime=60)