Комментарии:
# ****************************************************
# 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 it's time waiting for internal events (CPU intensive)
# use multiprocessing
# io bound = program/task spends most of it's time waiting for external events (user input, web scraping)
# use multithreading
import threading
import time
def eat_breakfast():
time.sleep(3)
print("You eat breakfast")
def drink_coffee():
time.sleep(4)
print("You drank coffee")
def study():
time.sleep(5)
print("You finish studying")
x = threading.Thread(target=eat_breakfast, args=())
x.start()
y = threading.Thread(target=drink_coffee, args=())
y.start()
z = threading.Thread(target=study, args=())
z.start()
x.join()
y.join()
z.join()
print(threading.active_count())
print(threading.enumerate())
print(time.perf_counter())
# ****************************************************
nice video bro
ОтветитьThis is brilliant .
Excellent explanation !!!
👏👏👏
meow~! uwu
ОтветитьTHAT IS ACTUALLY REALLY COOL NGL
ОтветитьFirstly thank you bro
Secondly if you guys have problem with main thread not printing 4then you must delete the() for writting the function in x=threading.thread()
Thanks for this
Ответитьbrooo you da bestt!!
Ответитьso simply, thankss
ОтветитьThank you for these clear and precise explanations.
As I am new to Python, this becomes very practical for my learning.
I would like that you showed an example like this : you can eat and drink at same time, but you must finish such activities to study.
Ответитьdobrze rozkminione :) Dziekowa
ОтветитьExcellent Explanation !!!
ОтветитьKindly revealed your face , we want to sees a person who know every language exist in this world
Ответитьyeah.. multi threading in the morning.. sounds familiar. like brushing teeth while getting the pants on.. =)
ОтветитьEven though you sound like 'Butthead' from 'Beavis & Butthead', I still love you 'Bro'. And thanks for your awesome tutorials. 👍🏻👍🏻
ОтветитьUnderstood in one go. Good work bro
ОтветитьTY bro
Ответитьhope the algorithm blesses your channel
Ответитьشكرا جزيلا
ОтветитьThank you!
ОтветитьSuch a wonderful explanation..
Ответитьshould i be concerned that when i run the same code as you i get "590447.4203372" returned from "print(time.perf_counter())"
Ответитьthank youuu
ОтветитьHey bro I've a problem.
Whenever I write my own code (following the same procedure) it shows only 1 thread and takes allotted time, but when I copy the given description code it and paste it, shows the 4 threads
Can't figure out why is it happening??
If you have problem with huge amount of time displaying by time.perf_counter() function here you have solve of this problem:
We can read in documentation:
time.perf_counter()
[...] The reference point of the returned value is undefined, so that only the difference between the results of two calls is valid.
So to solve it we have to declare variable before our code, for example:
starting_point = time.perf_counter()
...
our code here
...
print (time.perf_counter() - starting_point)
Super, finally i learn this argument! :) Nice work!!!
Ответитьate
Ответитьgreat explanation, loved the theory before the actual code
ОтветитьReally like how you go to the heart of the subject.. Concise and clear... Thanks..
ОтветитьGreat video thanks
ОтветитьWow!!!!!
Ответитьfor some reason my main thread waits for the other 3 threads to finish before it executes the print functions. i wrote the exact same code he wrote. anyone have an idea?
ОтветитьMy main tread is taking 734078.1110504 seconds to complete its task. what possibly could be the issue?
ОтветитьI really like how you explain everything so simply and quickly. Keep it up man !
ОтветитьFor I/O bound problems, it is better to use asyncio than threads. This gives less opportunity for race conditions and their consequent hard-to-reproduce bugs.
Ответитьamazing thank!s
Ответитьgreat explanation, thanks
Ответить>>> Very consistent explanation :)
>>> Could you please do this kind of tuts regarding python standart libr modules like Struct, OS, SubProcess and Select ?
>>> Have a good time
Bro.. 👏 Heads down.
ОтветитьHey I got this problem with Python showing 34568.4580 seconds while it only takes 3-4 seconds and it's not the only case in which this happens. Does anyone know how to display seconds correcty?
Ответитьyou sir are the best
ОтветитьMake a tutorial for flutter please beer is on me 🍺
Ответитьnice
ОтветитьThank you Bro
i run the exact same code but for me the time.perf_counter() returns a really big value for time taken sth like 11929.1326382 but in reality it takes 5 to 6 seconds to run i search online for solutions but nothing came out.
Any solutions?
Crystal Clear!
ОтветитьBest tutorial i have ever seen!
ОтветитьThank you very much
Ответитьbreh.... this is so clear...
Ответить