filmov
tv
Python multithreading 🧵
Показать описание
python threading multithreading tutorial example explained
#python #threading #multithreading
# ******************************************************
# Python threading tutorial
# ******************************************************
# thread = a flow of execution. Like a separate order of instructions.
# However each thread takes a turn running to achieve concurrency
# GIL = (global interpreter lock),
# allows only one thread to hold the control of the Python interpreter at any one time
# cpu bound = program/task spends most of its time waiting for internal events (CPU intensive)
# use multiprocessing
# io bound = program/task spends most of its time waiting for external events (user input, web scraping)
# use multithreading
import threading
import time
def eat_breakfast():
print("You eat breakfast")
def drink_coffee():
print("You drank coffee")
def study():
print("You finish studying")
x = threading.Thread(target=eat_breakfast, args=())
y = threading.Thread(target=drink_coffee, args=())
z = threading.Thread(target=study, args=())
#python #threading #multithreading
# ******************************************************
# Python threading tutorial
# ******************************************************
# thread = a flow of execution. Like a separate order of instructions.
# However each thread takes a turn running to achieve concurrency
# GIL = (global interpreter lock),
# allows only one thread to hold the control of the Python interpreter at any one time
# cpu bound = program/task spends most of its time waiting for internal events (CPU intensive)
# use multiprocessing
# io bound = program/task spends most of its time waiting for external events (user input, web scraping)
# use multithreading
import threading
import time
def eat_breakfast():
print("You eat breakfast")
def drink_coffee():
print("You drank coffee")
def study():
print("You finish studying")
x = threading.Thread(target=eat_breakfast, args=())
y = threading.Thread(target=drink_coffee, args=())
z = threading.Thread(target=study, args=())
Комментарии