2014-02-26 42 views
1

我在调制解调器工作时,会更改设置,并重启设备(在脚本中这一切都完成的)。所以,我需要来ping系统,等到设备了。延迟脚本,直到它执行ping到IP不睡觉

是我的尝试是

cur = time.time() 
delay = cur + 300 
while delay > cur: 
    t = os.system('ping '+ip) 
    if t: 
     something here 
    else: 
     something else here 

是否有任何其他方式做到这一点?基本的问题是,如何可以等待一些超时,直到一个设备了!

注:我在寻找一个解决方案,而time.sleep

回答

1

尝试使用time.sleep()像这样:

import time 

delay = 1 # this will delay for 1 seconds 
time.sleep(delay) 
+0

我正在寻找一种没有睡眠的方法。 – rajpython

0

,如果你想避免使用睡眠,你可以只改变而循环继续下去,直到你得到你的IP

waiting =True 
while waiting: 
    counter =0 
    t = os.system('ping '+ip) 
    if t: 
     waiting=False 
     do something 
    else: 
     counter +=1 
     if counter == 10000: # this will prevent an never ending loop, set to the number of tries you think it will require 
      waiting = False