简体   繁体   English

计划任务不断重复,永不停止

[英]Schedule task keeps repeating and never stops

def refresh_page():
    driver.refresh()

time.sleep(2)
while True:
    if driver.find_element(By.CLASS_NAME, "mask2").is_displayed() == True:
        break
    schedule.every(1).minute.at(":00").do(refresh_page)
    
    schedule.run_pending()
    time.sleep(1)

I was expecting it to only run the schedule command once, well it did work when it was not on ":00" seconds but as soon as it hits ":00" it keeps doing the task whenever it's possible to do so.我原以为它只运行一次调度命令,当它不在“:00”秒时它确实工作但是一旦它击中“:00”它就会在可能的情况下继续执行任务。 Btw the element is not displayed and I checked it so it could not be that line that's causing the problem (I think)顺便说一句,该元素未显示,我检查了它,所以它不可能是导致问题的那条线(我认为)

I think you need to put scheduling outside while loop, since it schedules multiple times:我认为您需要将调度放在 while 循环之外,因为它会调度多次:

def refresh_page():
    driver.refresh()

time.sleep(2)
schedule.every(1).minute.at(":00").do(refresh_page)
while True:
    if driver.find_element(By.CLASS_NAME, "mask2").is_displayed() == True:
        break
    
    schedule.run_pending()
    time.sleep(1)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM