嗨,我想在我的手机10分钟内无法phone通的时候执行一个函数
下面是我用来ping设备的当前代码:
ip = "192.168.1.187"
def ping(host):
param = '-n' if platform.system().lower()=='windows' else '-c'
command = ['ping', param, '1', host]
if subprocess.call(command) == 0:
print("Host is up")#executes function when host is up
wifi_connected()
else:
print("Host is down")
#here it should check if the device is longer than 10 minutes offline and execute a different function
ping(ip)发布于 2020-07-24 06:51:19
根据你想要什么,有两种解决方案。
首先,如果您只想在设备全部脱机10分钟的情况下执行。你将不得不不断地ping设备,把它放在一个循环,并重置计时器,每次它来on.Comparing最早的停机时间戳应该工作。
或
你可以获得它第一次离线的时间戳,并检查10分钟的延迟,使用
time.sleep(600)如果它仍然关闭,则执行代码
这取决于您的需求。
https://stackoverflow.com/questions/63064131
复制相似问题