【发布时间】:2012-05-23 11:22:14
【问题描述】:
我希望我的 python 脚本检查活动的互联网连接,如果有,则继续执行。如果没有连接,则继续检查。基本上阻止“main()”中的执行,直到脚本可以重新连接。
蟒蛇
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 不是你的私人研究助理:meta.stackexchange.com/a/128553
-
这能回答你的问题吗? Checking network connection