Sometimes you need to add delay to your specific code. Python has a built-in Sleep Function for such functionality. The sleep() function is part of the time module.
Using sleep() function in Python
Let’s take a look at how to use the sleep functions in Python. We will use the current time to check the time difference.
import time |
The following is the output.
Delay function execution
Use the time.sleep function in the user-defined function to delay the execution of the python function.
import time |
]
Adding delay using Event().wait function
In the threading library there is a function called event.wait() that can be used to add delay in the code.
from threading import Event |
Using Timer for delay
We can also use timer function to add delay to code.
from threading import Timer |