47. Sleep Function and Multithreading in Python with Code || Time Module Programming Tutorial

Published: 16 August 2022
on channel: Bhavatavi
102
0

The sleep() function suspends (waits) execution of the current thread for a given number of seconds.
Multithreading in Python enables CPUs to run different parts(threads) of a process concurrently to maximize CPU utilization.

Code:

import time
while True:
localtime=time.localtime()
result=time.strftime("%I:%M:%S %p",localtime)
print(result)
time.sleep(1)

import threading

def print_hello():
for i in range(3):
time.sleep(0.7)
print("Hello")

def print_hi():
for i in range(3):
time.sleep(0.9)
print("Hi")

t1=threading.Thread(target=print_hello)
t2=threading.Thread(target=print_hi)

t1.start()
t2.start()


On this page of the site you can watch the video online 47. Sleep Function and Multithreading in Python with Code || Time Module Programming Tutorial with a duration of hours minute second in good quality, which was uploaded by the user Bhavatavi 16 August 2022, share the link with friends and acquaintances, this video has already been watched 102 times on youtube and it was liked by 0 viewers. Enjoy your viewing!