Python在while循环中计算异常

时间:2016-05-25 15:12:44

标签: python python-2.7 loops selenium exception

我正在尝试计算例外情况。我需要脚本在25超时异常和关闭/打开wifi连接后警告我,之后继续该过程。我正在使用下面的代码,但是循环有问题,它警告我和关闭wifi连接3次(3x25),然后在它应该是无限循环时停止。

count = 1
while True:
    try:
        browser.get("url")
        return
    except selenium.common.exceptions.TimeoutException:
        print "Timeout..."
        count += 1
        if count >= 25:
            print 'There is a problem with connection'
            os.system("networksetup -setairportpower en1 off; networksetup -setairportpower en1 on")
            count = 1
            time.sleep(5)

0 个答案:

没有答案
相关问题