I am writing a code to run a gui application(winmerge) and then send some keystrokes to it. I need to wait for some time within the program till the GUI finishes running and then send some keystrokes to it to save the report. How do I implement this? wait()
isn't working as after invoking it I can't send keys to the same window.
Adding a Python sleep() Call With time.sleep() The time module has a function sleep() that you can use to suspend execution of the calling thread for however many seconds you specify. If you run this code in your console, then you should experience a delay before you can enter a new statement in the REPL.
Sometimes we want our python program to wait for a specific time before executing the next steps. We can use time module sleep() function to pause our program for specified seconds.
Though there are a plethora of ways to make a pause in Python the most prevalent way is to use the wait() function. The wait() method in Python is used to make a running process wait for another function to complete its execution, such as a child process, before having to return to the parent class or event.
Here is another example where something is run approximately once a minute: import time while True: print("This prints once a minute.") time. sleep(60) # Delay for 1 minute (60 seconds). Save this answer.
from time import sleep
print "hi,"
sleep(5)
print "this is printed 5 seconds later"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With