Learn Python multithreading in 8 minutes! 🧵

Опубликовано: 16 Июль 2024
на канале: Bro Code
55,050
1.9k

#python #pythonprogramming #pythontutorial

multithreading = Used to perform multiple tasks concurrently (multitasking)
Good for I/O bound tasks like reading files or fetching data from APIs

import threading
import time

def walk_dog(first, last):
time.sleep(8)
print(f"You finish walking {first} {last}")

def take_out_trash():
time.sleep(2)
print("You take out the trash")

def get_mail():
time.sleep(4)
print("You get the mail")

chore1 = threading.Thread(target=walk_dog, args=("Scooby", "Doo"))
chore1.start()

chore2 = threading.Thread(target=take_out_trash)
chore2.start()

chore3 = threading.Thread(target=get_mail)
chore3.start()

.join() ensures that all tasks are completed before proceeding
chore1.join()
chore2.join()
chore3.join()

print("All chores are complete!")


На этой странице сайта вы можете посмотреть видео онлайн Learn Python multithreading in 8 minutes! 🧵 длительностью часов минут секунд в хорошем качестве, которое загрузил пользователь Bro Code 16 Июль 2024, поделитесь ссылкой с друзьями и знакомыми, на youtube это видео уже посмотрели 55,050 раз и оно понравилось 1.9 тысяч зрителям. Приятного просмотра!