The sleep function is used to pause the execution of a current thread for a given number of seconds or milliseconds, depending on the programming language being used. So, what is a thread?
Every computer program contains a series of instructions; the execution of these instructions is known as a process. A thread is the smallest subset of a process.
For the code below, if you click the run button, you will see that its execution time is around to seconds.
print("Printed immediately.")
Now, using the sleep function in Python, the print
function should run seconds after the code is run. The execution time should be around - seconds.
import timetime.sleep(2.4)print("Printed after 2.4 seconds.")
Free Resources