3
我想讓我的python腳本檢查一個活動的互聯網連接,如果有一個然後繼續執行。如果沒有連接,請繼續檢查。基本上阻止執行「main()」,直到腳本可以重新連接。python等到連接激活
蟒蛇
import urllib2
def main():
#the script stuff
def internet_on():
try:
response=urllib2.urlopen('http://74.125.113.99',timeout=1)
main()
except urllib2.URLError:
internet_on()
Stack Overflow是不是你個人的研究助理:http://meta.stackexchange.com/a/128553 –
^^感謝您的評論... – Blainer