Python在while循环中计数异常

2024-05-19 11:04:06 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在计算例外情况。我需要脚本在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)

Tags: 代码脚本true警告过程countwifi例外情况

热门问题