简体   繁体   中英

How to run a specific function on a specific time in Python?

I am creating an automation script using pyautogui to click on a specific href text 'Start'. This text moves to the next section on the same page after 2 hours. Is there a module which can be used to tell the current time and if the time is in the specified interval then run a function like def(func1), if the condition satisfied for second interval then run def(func2)

One way is to just store the current time from time.time() in a variable, make a while loop and check if the difference between time.time() and that variable is greater than the time you want to wait for.

import time
start_time = time.time()

while (start_time - time.time() < time_in_seconds_to_wait):
    pass

# rest of the code that gets executed after the wait

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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