Python Threading Tutorial: Run Code Concurrently Using the Threading Module

  Рет қаралды 853,531

Corey Schafer

Corey Schafer

Күн бұрын

Пікірлер
@coreyms
@coreyms 5 жыл бұрын
Hey everybody! I hope you find this video helpful. I'll be releasing the multiprocessing video next week. I am currently packing up my temporary recording station and will be moving into my new place tomorrow, so I should be able to get it recorded, edited, and released next week for sure. We'll be covering how to use multiprocessing to process the high-resolution images we downloaded in this video. Hope you all get some good use out of these topics!
@youssefelbiyadi4285
@youssefelbiyadi4285 5 жыл бұрын
Hi corey Thank you very much for this topic it's quite interesting, your videos are very helpful. I have a view function in my django project that performs some complicated calculations, so it is CPU Bound. The problem is that when I run these calculations for a high number of objects (each object is an eNodeB site), it takes a while before loading the view page. I tried to use threading but it was not useful. So I wanna use multiprocessing but I have a problem with the __name__=="__main__" condition. I can't use it in Django framework... Do you have any other suggestions for me please that will be very helpful ? Thank you again for all your efforts :)
@coreyms
@coreyms 5 жыл бұрын
@@youssefelbiyadi4285 Hey there. When it comes to running asynchronous tasks on web applications, it might be a good idea to use a messaging task queue (e..g Celery). Anthony over at the PrettyPrinted channel released a video just the other day on how to do this. I think he did a great job. Check that out here: kzbin.info/www/bejne/mF6Znnh3p5agY6M
@youssefelbiyadi4285
@youssefelbiyadi4285 5 жыл бұрын
@@coreyms Tkanks a lot that was very helpful
@gingerboy9170
@gingerboy9170 5 жыл бұрын
Waiting for the next "IMG processing" vid sensei....🔥🔥🔥
@marcelodimb
@marcelodimb 5 жыл бұрын
Hi @Corey Schafer, please, can you make a tutorial explaining how we create a python web application (Django or Flask) using Docker? I love your videos. Best regards from Brazil!
@HexagonalClosePacked
@HexagonalClosePacked 5 жыл бұрын
When I first tried to switch my career to programming, I watched Corey's videos. Now, 3 years later, I already got a job in programming and still watch Corey's videos :)
@dnetne5508
@dnetne5508 4 жыл бұрын
Damn - that is amazing!
@ksun8993
@ksun8993 4 жыл бұрын
@HexagonalClosePacked So basically you have your rank /Z effective as 6 with 2 corner atoms,3 body and 2 face atoms . And Zn and Mg adopt your structure. (To understand , read your username)
@kwertie133
@kwertie133 4 жыл бұрын
@@ksun8993 iit?
@K3vyB
@K3vyB 3 жыл бұрын
@@kwertie133 I unleashed a vile shit just now bro
@muralidhar40
@muralidhar40 2 жыл бұрын
Same here!
@nicholastalbot6370
@nicholastalbot6370 4 жыл бұрын
Corey: I know that sounds confusing. Me: No, you explained that very well.
@edwingarcia5043
@edwingarcia5043 3 жыл бұрын
Unfortunately some things sound confusing, I mean, it heavy depends on my current knowledge, the good thing about Corey is the calm way of explaining.
@edwingarcia5043
@edwingarcia5043 3 жыл бұрын
@Slime Boi wadafa :0
@dipankarkaushik5285
@dipankarkaushik5285 5 жыл бұрын
Was waiting for this topic to learn from the world's best Python Mentor. Now the wait is over. God bless you.
@saraljoshi1
@saraljoshi1 5 жыл бұрын
“hear hear"..exactly my sentiment. After trying concurrency in python on my own several times and failing. I knew only Corey's Videos will help.
@kebman
@kebman 4 жыл бұрын
If you threaded the timer the wait would be much shorter....................
@PyjamasBeforeChrist
@PyjamasBeforeChrist 3 жыл бұрын
time.sleep(0)
@kirubababu7127
@kirubababu7127 3 жыл бұрын
Hi Bro, If I am trying to read CSV files by pandas,time duration is not reducing. Could suggest your ideas?
@CodeWithGBMags
@CodeWithGBMags 3 жыл бұрын
I agree, this was really helpful @Corey, you are my favorite Python mentor and so is your channel
@CwMuller
@CwMuller 5 жыл бұрын
Had a service at work that created html pages with indexes of hundreds of xml reports. It used to read each report one by one. Used what I learned here to refactor the code to process files concurrently, which cut the script run time to a fraction of what it used to run at. Thanks for the fantastic tutorial!
@coreyms
@coreyms 5 жыл бұрын
That's awesome! Good work!
@ismersh
@ismersh 5 жыл бұрын
The best video in the internet about multithreading. Clear and step by step detailed explanation about different ways to run multiple threads in your script + Corey explained why the threading is useful, while some websites tend to say multithreading doesn't work in python. We are very lucky that we have Corey explaining these concepts for free in KZbin, because you won't find such good materials even in paid courses on Udemy or other sites.
@coreyms
@coreyms 5 жыл бұрын
Thanks!
@pacoa-kdbg9303
@pacoa-kdbg9303 2 жыл бұрын
Almost 2 years since you uploaded this, you reduced my exect time from ~90 mins to ~2 mins at max . Awesome videos, will continue watching
@paulh4654
@paulh4654 5 жыл бұрын
You are not only the master of this subject matter, but also you are a great communicator who can articulate artfully. I appreciate your time and effort to share your gift with all of us. Thank you so much.
@AnselJanson-v5v
@AnselJanson-v5v Жыл бұрын
still valid even after 3 yrs Awesome tutorial
@dangidelta
@dangidelta 4 жыл бұрын
Mind Blown : 100% New Concept : Yes Easy Implementation : Yes More Control on Programs from now on : Yes Feel like a New Level Achieved : Definitely Yes
@harrisongropper199
@harrisongropper199 3 жыл бұрын
I agree
@vishnusingh4118
@vishnusingh4118 5 жыл бұрын
Crystal-friggin'-clear! The coolest part was the real-world examples at the end which ensured there was a concrete takeaway and that it wasn't all just theoretical. The best threading vid on the internet! You keep getting better Corey. More power to you !
@adobongasin214
@adobongasin214 3 жыл бұрын
For those who are starting in Python, Corey is the best in terms of explaining things, I am already a Team Lead but I still go back to his tutorials once in a while hahaha
@excitedbox5705
@excitedbox5705 4 жыл бұрын
This has to be the best made guide ever. This should exist for every programing language. Usually guides only give you the absolute basics and expect you to figure out the more advanced stuff yourself and that is where most people get stuck. The level of detail in this is perfect without making it overly long.
@gytisbl
@gytisbl 2 жыл бұрын
Really liked the distinction at 4:27 that its best to use several threads when code is IO bound: -reading/writing disk, waiting for network
@o1techacademy
@o1techacademy 2 жыл бұрын
Thank you for this powerful tutorial.
@gurudevilangovan
@gurudevilangovan 4 жыл бұрын
You definitely do have a gift. It takes a ton of talent to explain concepts like this with so much lucidity. Whenever someone says they want to learn python, I point them right to your videos. Thanks Corey! I'm indebted to your videos.
@anantchopra1663
@anantchopra1663 2 жыл бұрын
This video is a life-saver! I have a project due in 3 days that needs me to do a lot of fancy stuff in a multithreaded program, and I had no clue what multithreaded programs are! I'm in a much better position after watching this video. Thank you, Corey!
@andrewhofmann5453
@andrewhofmann5453 3 жыл бұрын
So I just extended the Thread class into my own class and made something so much more efficient because of this video. Great job!
@newpain01
@newpain01 2 жыл бұрын
Completely agree about the basic example tutorials, I often find them useless. Great video, thanks!
@ZbigniewLoboda
@ZbigniewLoboda 3 ай бұрын
❤ At last, I have found an instructor-you-who truly understands and knows what they are talking about in the subject of Python programming.
@orkhanahmadov9963
@orkhanahmadov9963 3 жыл бұрын
This man deserves a golden globe award... I have been watching his videos for the last 3 years. He helped me to master Python.. I would definitely like to recommend this channel to anyone who wants to learn CS.
@DarshitParmar
@DarshitParmar 4 жыл бұрын
You are an angel. Most youtubers teach textbook. Thank you so much for this tutorial!
@EdiFerreiranet
@EdiFerreiranet 5 жыл бұрын
10:54 Throw away variable!?! Nice!!! I didn't knew that. Awesome!!! Thank you. You're the best ;)
@bratergames9410
@bratergames9410 2 жыл бұрын
For five years I was looking for some simple explanation that I could use in my code, to pull my dna, from snpedia...OMG. So simple but very good. Thanks man.
@juliocefe1807
@juliocefe1807 3 ай бұрын
OMG, one of the best programming channels on KZbin
@okyigwegbe1977
@okyigwegbe1977 4 жыл бұрын
Corey, you are unbelievably good. My python journey has been solid because of your brilliant and simplistic way of explaining the most complex of things. Thank you very much and God bless you.
@victorialeigh2726
@victorialeigh2726 3 жыл бұрын
I click it all excited to master threading in 30 minutes. In the first 10 seconds, I realise it's an intensive lecture so I need to take notes. After 2 hours I have 10 minutes left lol (but I know this will go a long way) Edit: after 3 hours I completed the tutorial. Now I'm gonna go improve my code.... thank you Corey!
@truongtran99_
@truongtran99_ 8 ай бұрын
Your explanation about threading was so clear and easy to understand. Thank you for making this video!
@hotcrossbun26
@hotcrossbun26 Жыл бұрын
I'd be so screwed without your videos. The BEST explanations anywhere on the internet for learning python.
@georgesd9
@georgesd9 4 жыл бұрын
Thank you Corey, channels like yours is what makes youtube worth visiting IMHO. One thing I needed to add, I tried to use threading on a sending email method in flask to avoid delay in redirecting, I found out that it can't be used out of the box, due to flask app-context, with some research I managed to make it work, by researching more about flask contexts I ended up using flask-script with Manager and Shell classes, using the shell to create a context for the thread. I'm writing this in case someone is trying to do the same.
@terryhenyo9216
@terryhenyo9216 5 жыл бұрын
When I see a Corey Schafer video I automatically like before watching, because I know it's going to be good :)
@derrick7968
@derrick7968 5 жыл бұрын
Me too, i commented without watching
@fergusonsofstirling8130
@fergusonsofstirling8130 4 жыл бұрын
Thank you very much Corey. I couldn't get my head around threading before watching your video. After adapting my code with concurrent.futures.ThreadPoolExecutor() / executor.map I managed to speed up a program that makes API calls - which is now at least 100 times faster!
@Mrslykid1992
@Mrslykid1992 4 жыл бұрын
Wow parenthesis throws everything off! Thank You Corey! from com.project.src.Experimentation.GatherDataWithThreads.GatherData import GatherData from com.project.src.Experimentation.GatherDataWithThreads.ThreadingData.ThreadData import ThreadingData class ThreadingDataTest(unittest.TestCase): def test_durationOfThreadIsAtleast3Sec(self): start = time.perf_counter() gd = GatherData() gd.getDataSource1() gd.getDataSource3() finish = time.perf_counter() self.assertTrue(finish-start>3) def test_durationOfThreadsIsLessThan3Sec(self): start = time.perf_counter() gd = GatherData() td = ThreadingData() thread = td.createThread(function=gd.getDataSource1) thread2 = td.createThread(function=gd.getDataSource3) td.startThread(thread) td.startThread(thread2) threadList = [] threadList.append(thread) threadList.append(thread2) td.joinThread(thread) td.joinThread(thread2) finish = time.perf_counter() self.assertTrue(finish-start < 3)
@trevormckellen5613
@trevormckellen5613 3 жыл бұрын
The reason I've learned so much from your videos is real world application. I hit a wall with all the tutorials online until I found this channel. Thank you Corey
@alttablife6965
@alttablife6965 2 жыл бұрын
Easy choice to subscribe. These are helping me learn more in a few days than combing through docs did in a week. For reference, I'm coming primarily from a bash background. Last time I looked at multiprocessing was in a college java class. This just refreshed almost everything I need for my current project.
@chazyua
@chazyua 5 жыл бұрын
OMG. This is not the first time you read my mind. Literally just wanted to find some threading topics ! Wow ! Thanks
@PatooOfficial
@PatooOfficial 4 жыл бұрын
At first I thought this was some video from annoying courses companies that's just a waste of time and boring.. until the video started I got happy and knew this video is quality from a quality channel
@TheFred10000
@TheFred10000 5 жыл бұрын
This channel is criminally underrated.
@luffingsails7542
@luffingsails7542 2 жыл бұрын
Tried Skillshare to take on learning Python. There is a bunch of milquetoast videos with no real substance. These videos by Corey are outstanding. Much appreciation. I'm glad it was a free subscription.
@Sharmapawan98
@Sharmapawan98 5 жыл бұрын
Can we have this man rewrite the official docs of python ? Love from India♥
@BoukariYameogo
@BoukariYameogo 5 жыл бұрын
Corey is really a great teacher
@massiveblackwood
@massiveblackwood 5 жыл бұрын
indeed, idk why they refer a link to the same page and hyperlink it on every word on those page now i'm suffering vertago bcs of that thanks for words!
@BoukariYameogo
@BoukariYameogo 5 жыл бұрын
How come some people could dislike your videos? I really don't understand it. You're doing a great job for real. Thank you for your videos
@cetilly
@cetilly 3 жыл бұрын
Easily the best presentation on multi-threading and ThreadPoolExecutor that I've seen. Really great job.
@dano2169
@dano2169 5 жыл бұрын
Literally so many videos out there on threading and multiprocessing but by far this is the best. Thanks Corey!
@sanviews9819
@sanviews9819 4 жыл бұрын
One of the best Educator on programming out there ... love from India.
@chawza8402
@chawza8402 2 жыл бұрын
Thank you very much! best python guide in all KZbin Although I only watch until 15:23, I have learned alot
@mengzhu8385
@mengzhu8385 3 жыл бұрын
Most clear video on explaining multi-threading in Python!
@mohit4u007
@mohit4u007 4 жыл бұрын
Your threading and multiprocessing videos helped me a lot to solve my problem at work. Thanks a millions. Awesome effort and great wishes to you. Keep going!!!
@MyYouthUk
@MyYouthUk 3 жыл бұрын
I'm currently only half way through... but this is far more comprehensive than anything else I've found. Easy to understand and detailed at the same time.
@LiquidArremer
@LiquidArremer 5 жыл бұрын
I think the best part of these tutorials are the ones were you involve real world examples to show the utility, especially common cases and how it alters from then to now. Keep up the good work Corey!
@wassimracing
@wassimracing 3 жыл бұрын
You sir, are a HERO. I don't usually hit the red button, but you deserve it! Thanks!
@touchpad24
@touchpad24 3 жыл бұрын
Your explanation is so simple yet at the same time covers everything. Thanks so much!
@JohnJohnson-db4vv
@JohnJohnson-db4vv 3 жыл бұрын
Honestly, been wanting to figure out threading for the better part of a year now and every tutorial I've followed thus far has been confusing and doesn't explain a lot of important details. Thanks to this video I finally have been able to figure out threading!
@gastonscazzuso4113
@gastonscazzuso4113 3 жыл бұрын
Corey , this is the best explained Threading topic video in KZbin !.. Awesome.. and many Thanks !
@jaylocker2055
@jaylocker2055 4 жыл бұрын
LOL, just cut a loop that makes 12,000+ API calls from 42 minutes to < 5 minutes. This is freakin awesome!
@diegomedflo
@diegomedflo 4 жыл бұрын
How do you avoid being banned? proxies?
@jaylocker2055
@jaylocker2055 4 жыл бұрын
@@diegomedflo I'm hitting an internal service our company uses. Wish I could do batch requests, but the info I needed had to be a per record request as noted in the services documentation.
@moeinmhzg7827
@moeinmhzg7827 3 жыл бұрын
I don't remember if I saw any better python tutorials. You are the best.
@jaehochoi8062
@jaehochoi8062 2 жыл бұрын
Clear, easy, pinpoint, reliable plus truly helpful explanation ever!
@mehdibouss4551
@mehdibouss4551 5 жыл бұрын
happy hear from u again,.The Mathplot videos were awesome.i saw also all the other videos.Keep going ,U got the juice of python man ! wating for more about data science...
@jerry5646
@jerry5646 5 жыл бұрын
Hands down. Best python tutorial in youtube
@borja4015
@borja4015 4 жыл бұрын
These videos were really well explained. I had been curious for a time about multithreading VS multiprocessing and I feel like I learned a lot from your videos
@athisii_ekhe6167
@athisii_ekhe6167 4 жыл бұрын
Your videos doesn't want me to stop. I'm addicted to it. Cos its the best. Thank you. MGBY.
@davidnago7947
@davidnago7947 4 жыл бұрын
@Corey you need an award for the top quality content . keep it up
@fredpaik1349
@fredpaik1349 5 жыл бұрын
Thank you Corey for ALL your videos! You are an inspiration and a great teacher. Keep up the good work!
@tuvshinotgo5911
@tuvshinotgo5911 4 жыл бұрын
Stop Corey, you are killing it. Kidding no stop
@Nickelkitten75
@Nickelkitten75 11 ай бұрын
Very clear and concise explanation Kudos Corey
@vishnusingh4118
@vishnusingh4118 5 жыл бұрын
35:03 Yes yes yes ! Please make the vids on the advance topics as well! That will complete the knowledge-pack and make this video even more fruitful as we'll be able to apply the knowledge end-to-end in a real world setting. Thanks a ton Corey.
@derrick7968
@derrick7968 5 жыл бұрын
Corey your the best, love your simplicity and cool examples. I use python for QA automation . Much appreciation from this side of the globe - Kenya.
@shinobi9461
@shinobi9461 4 жыл бұрын
Your tutorials are truly phenomenal. Thank you so much for sharing these videos with everyone, they’re incredible!
@SlaineCZE
@SlaineCZE 5 жыл бұрын
Brilliant explanation (as always). Thank you, Corey. It would be great if you did the more advanced threading/multiprocessing (GIL etc.) video that you suggested.
@soumyazyx
@soumyazyx 4 жыл бұрын
More I see these videos, more do I fall in love with python and Corey. Thank you for your time and effort.Keep spreading the knowledge.
@azemashaik4301
@azemashaik4301 Жыл бұрын
Thank you so much, Corey, for this fantastic tutorial on introducing threading in Python to beginners! Your clear explanations and step-by-step demonstrations have really helped me grasp this concept much better. Your tutorials are always a go-to resource for me, and I appreciate how you make even complex topics so accessible. Your contribution to the Python community is invaluable, catering to both newcomers like me and experienced developers. Keep up the fantastic work, Corey!
@dataenergy
@dataenergy 9 ай бұрын
clear, concise and with provided example... excellent!!
@somaloco3701
@somaloco3701 5 жыл бұрын
omgggg I wanted to learn this but didn't because it seemed too advanced. thank you corey, there is no better source to learn from than you, I can learn anything that you teach!
@yuliiakhalus7339
@yuliiakhalus7339 4 жыл бұрын
Thank you very much for this tutorial! No one can explain all this Python stuff better that you!
@arunprakasam.s
@arunprakasam.s 3 жыл бұрын
Great tutorial on Threading. Thanks, Corey, Explanation is at the perfect pace, not needed to increase or decrease the playback speed.
@spoonmanchen7631
@spoonmanchen7631 5 жыл бұрын
You never let me down, My Instructor. Always looking forward to your next video.
@smithatubeme
@smithatubeme 5 жыл бұрын
Thanks Corey! Can you please also do a tutorial on dockers?
@letslearnabout4934
@letslearnabout4934 5 жыл бұрын
Brilliant video as always, Corey. I love that it is not just theory or theory with a few "FooBar" examples, but real world applications.
@stephenrwafa2519
@stephenrwafa2519 4 жыл бұрын
Awesome, simply awesome and had to watch ads all the way to the end in appreciation this level of quality. Thanks
@karansmittal
@karansmittal 3 жыл бұрын
It was a very demanded video, Thanks for working on it. Always creating high quality video content.
@pahehepaa4182
@pahehepaa4182 4 жыл бұрын
Hands down, best instructor.
@ahmedabdulrahman8567
@ahmedabdulrahman8567 5 жыл бұрын
your fan from Sudan ... thanks for making such unique content
@isaacfink123
@isaacfink123 5 жыл бұрын
I have watched almost all of your python videos, and I've been waiting for something like that for a very long time, Thanks corey
@mostafanakhaei4916
@mostafanakhaei4916 4 жыл бұрын
Corey Your ability to teach is amazing.
@Mainhunpyarkamusafir
@Mainhunpyarkamusafir 2 жыл бұрын
No one can explain better than you
@ravikumaroruganti2097
@ravikumaroruganti2097 4 жыл бұрын
Explained multi threading concept with perfect example.Thanks Corey!
@leondaz
@leondaz 5 жыл бұрын
I watched the AD till the end and clicked on it, Thanks man
@uguree
@uguree 4 жыл бұрын
Thanks a lot, what a brilliant video. Your english, real examples (sick and tired of hello worlds!) everything perfet. I will subscribe the Brilliant.org after watching this.
@26_dharmeshmarathe86
@26_dharmeshmarathe86 2 жыл бұрын
You're great. Your video on multithreading helped me to undertand the differncce between multithread & multiprocess. Great explaination!!❤❤
@alexchung485
@alexchung485 4 жыл бұрын
You have saved my project! I was looking for the return of a thread process everywhere! Thank you!
@nickvledder
@nickvledder 3 жыл бұрын
Covey, you must be God-sent. Thanks for this thorough explanation!
@dinohunter7176
@dinohunter7176 4 жыл бұрын
The examples are so well done and nice explained. Good stuff.
@bendibhafed1687
@bendibhafed1687 2 жыл бұрын
Very clear and amazing course, thank you sir
@johnnymysto
@johnnymysto 3 жыл бұрын
Great explanation!! I knew basically nothing about this before I watched it, and it makes complete sense now.
@elgary9074
@elgary9074 2 жыл бұрын
Long videos yes, but what a great explanation totally worth the time. Thanks a lot.
@patloeber
@patloeber 5 жыл бұрын
Great Tutorial!
@sunilthapa6702
@sunilthapa6702 4 жыл бұрын
Awesome Video!...Finally understood Threading in Python...Thanks for the video!
@luanangtranhuu1919
@luanangtranhuu1919 3 жыл бұрын
this is better than any lecture I have had at my university. 😊 thanksss
@pranayb4115
@pranayb4115 5 жыл бұрын
Clear & concise explanation on I/O vs CPU bound tasks. Looking forward for a video series on "asyncio" library.
@ReCremisi89
@ReCremisi89 3 жыл бұрын
Amazing video as always. I started knowing basically nothing about the topic. Now I have a strategy to replace my for loops with functions, and to make batches of function calls. An interesting idea for a future video would be on how to combine multi-threading with multi-processing: Your example on image processing represents an interesting real world scenario where you need to perform a task that is I/O bound in some parts and CPU bound in others.
@11rshan
@11rshan 2 жыл бұрын
Viewed everything on the net. Nothing like this. Best video for threading
5 Good Python Habits
17:35
Indently
Рет қаралды 676 М.
BAYGUYSTAN | 1 СЕРИЯ | bayGUYS
36:55
bayGUYS
Рет қаралды 1,9 МЛН
My scorpion was taken away from me 😢
00:55
TyphoonFast 5
Рет қаралды 2,7 МЛН
IL'HAN - Qalqam | Official Music Video
03:17
Ilhan Ihsanov
Рет қаралды 700 М.
Get JOB READY in 6 Months with AI-Powered Cohort and Expert Guidance
39:39
Sheryians Coding School
Рет қаралды 12 М.
Next-Level Concurrent Programming In Python With Asyncio
19:19
ArjanCodes
Рет қаралды 184 М.
How I animate 3Blue1Brown | A Manim demo with Ben Sparks
53:41
3Blue1Brown
Рет қаралды 1,2 МЛН
threading vs multiprocessing in python
22:31
Dave's Space
Рет қаралды 600 М.
PLEASE Use These 5 Python Decorators
20:12
Tech With Tim
Рет қаралды 126 М.
3 PYTHON AUTOMATION PROJECTS FOR BEGINNERS
17:00
Internet Made Coder
Рет қаралды 1,7 МЛН
Avoid These BAD Practices in Python OOP
24:42
ArjanCodes
Рет қаралды 81 М.
Unlocking your CPU cores in Python (multiprocessing)
12:16
mCoding
Рет қаралды 312 М.
How I Would Learn Python FAST (if I could start over)
12:19
Thu Vu data analytics
Рет қаралды 657 М.
BAYGUYSTAN | 1 СЕРИЯ | bayGUYS
36:55
bayGUYS
Рет қаралды 1,9 МЛН