Interface Locking

The interfaces in this chapter are used to lock all API interfaces, so that the interfaces can only be used by the current Device instance, preventing the API from being used by other users or processes. You can set a default lock duration, periodically refresh the lock (recommended to refresh periodically), or actively release the interface lock.

Acquire Lock

Acquire the lock. This lock will be automatically released after 60 seconds. Once released, other clients can acquire the lock. You can change this duration, but if set too long, once the script exits abnormally, you will barely be able to connect to the device, and you may need to restart the device to reconnect. This interface is reentrant, and reentrant calls are 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 the specified leaseTime. Please call this interface periodically to maintain API locking. Similarly, if leaseTime is set too high, once the script exits abnormally, you will barely be able to connect to the device.

d._refresh_lock(leaseTime=60)