首页 > 解决方案 > windows上是否有任何adb等待设备超时方法

问题描述

我想使用限时 adb wait-for-device ,但似乎没有超时功能,我的解决方法如下,有没有更有效的方法来实现它?

<python on Windows>
                    t0 = datetime.datetime.now()
                    cmd = 'date'
                    cmd = 'adb -s %s shell \"'+ cmd+ '\"'
                    r = 1
                    while(r!=0 and (t1-t0).seconds < 60):
                        r = os.system(cmd)
                        t1 = datetime.datetime.now()

标签: adb

解决方案


没有可用的特定超时方法,但您可以尝试

def wait_for_device(self, timeout=5):
    """
    Perform `adb wait-for-device` command

    Args:
        timeout: time interval in seconds to wait for device

    Raises:
        DeviceConnectionError: if device is not available after timeout

    Returns:
        None

    """
    try:
        self.cmd("wait-for-device", timeout=timeout)
    except RuntimeError as e:
        raisefrom(DeviceConnectionError, "device not ready", e) 

推荐阅读