Threading Tutorial #2 - Implementing Threading in Python 3 (Examples)

  Рет қаралды 149,611

Tech With Tim

Tech With Tim

4 жыл бұрын

This threading tutorial discusses how to use the threading module in python 3 and goes over some examples of using multiple threads. The python version used in this video is python 3.8 and threading is implemented with the newest version of the threading module.
Playlist Link: • Threading Tutorial #1 ...
◾◾◾◾◾
💻 Enroll in The Fundamentals of Programming w/ Python
tech-with-tim.teachable.com/p...
📸 Instagram: / tech_with_tim
🌎 Website techwithtim.net
📱 Twitter: / techwithtimm
⭐ Discord: / discord
📝 LinkedIn: / tim-ruscica-82631b179
📂 GitHub: github.com/techwithtim
🔊 Podcast: anchor.fm/tech-with-tim
💵 One-Time Donations: www.paypal.com/donate/?token=...
💰 Patreon: / techwithtim
◾◾◾◾◾◾
⚡ Please leave a LIKE and SUBSCRIBE for more content! ⚡
⭐ Tags ⭐
- Tech With Tim
- Python Tutorials
- Python 3 Threading
- Threading Python
- Thread Tutorial Python
- Threading Module Python
⭐ Hashtags ⭐
#Python #Threading #Concurrency

Пікірлер: 165
@TechWithTim
@TechWithTim 4 жыл бұрын
Had some audio issues with the previous upload but seems to be working now! Let me know if there any other *bugs* in the video!
@akshatsingh7286
@akshatsingh7286 4 жыл бұрын
Yea Ik it said Private vid. Love you btw!! Please make a ML from basics video
@SkyFly19853
@SkyFly19853 4 жыл бұрын
Oh, I was wondering about that... That's OK as long as this video works.
@dwarkeshhaldankar2612
@dwarkeshhaldankar2612 4 жыл бұрын
Make the next video in this series. I wanna learn more!!
@3ngineer427
@3ngineer427 3 жыл бұрын
you said you'll cover the global memory accessing, fixing the issue with block @10:20 but the new video didn't show up? Maybe it's because you're too busy, but it might be helpful if you forgot the put a new video for this one :) BTW, you're an awesome teacher so far bro!!
@AbhishekSingh-du5di
@AbhishekSingh-du5di 3 жыл бұрын
Oh my god, You saved my project thanks a lot! Stay blessed tim
@dguiles1
@dguiles1 2 жыл бұрын
Dude Tim. You literally taught me threading in python in ten minutes, flawlessly. I am extremely humbled by your thorough understanding and willingness to teach others. Thank you! Your videos are literal gold for autodidactic individuals.
@LuisPereira-bn8jq
@LuisPereira-bn8jq 4 жыл бұрын
Awesome video. I wanted to implement a little threading in a mini project for webscrapping definitions from an online dictionary and this quickly taught me 80% of what I needed.
@alank1995
@alank1995 2 жыл бұрын
You have a way of making things simple and easy to digest. I watched a few other videos before yours and left with more confusion than when I started. Half way through your video it all clicked. Thanks for the help!!!
@javiarroyo8358
@javiarroyo8358 4 жыл бұрын
i have been struggling with thread for weeks till u suddenly decided to do this tutorial, tyvm bro, u are really helping me to truly understand how python and coding works
@aldairdejesushoyostorres4940
@aldairdejesushoyostorres4940 2 жыл бұрын
Thanks a lot, Tim. I've been trying to understand this concept so many times without succeding. Your explanation here together with the theoretical basis given in the previous part gave me a clear picture of how this works and how to implement it in my code. Thanks again, you have a great channel.
@ohwow2074
@ohwow2074 4 жыл бұрын
maaan your explanations are awesome!!! Never seen a simple explanation like this
@utpalmohane1416
@utpalmohane1416 2 жыл бұрын
Lately I watch and practice practically on my computer along with your video and this has helped me a lot. Your explanation was mind- boggling and your speech is clear. Thanks and keep up the great work.
@numberiforgot
@numberiforgot 3 жыл бұрын
I wish I had discovered your channel back when I first started programming. Would have saved me months. You talk and instruct just like a college level professor. Easy to understand and you don't digress at all.
@ue5dev617
@ue5dev617 4 жыл бұрын
Very very interesting ! Thanks so much for your explanation, you made it crystal clear. Please continue on this serie as much as you can (and also multiprocessing if possible) You're amazing ! Keep up the good work !
@junaidmahmud2894
@junaidmahmud2894 Жыл бұрын
It was a delight watching this tutorial. Nicely explained with a great sequence!
@milanpaudel9624
@milanpaudel9624 4 жыл бұрын
Sound quality is awesome and loud. I'm glad you sort it out. Always supporting you forever.
@TechWithTim
@TechWithTim 4 жыл бұрын
:)
@frozen7535
@frozen7535 3 жыл бұрын
Perfect vid, tim gave the explanation plus the examples i needed
@sma92878
@sma92878 Жыл бұрын
This is a really solid explination, nicely done.
@zedhelion
@zedhelion Жыл бұрын
massive thank you my man, helped me understand and execute the basics of threading!
@SandipPoddar
@SandipPoddar 4 жыл бұрын
Good work Tim, keep it up. Supporting you forever, learnt a lot from you and expecting much more videos from you. Nice explanation and example. Motivated me a lot. Want more and more "Expert Python Tutorial" and Threading videos. Lots of love from INDIA.
@willraasch7816
@willraasch7816 Жыл бұрын
This was the answer to my biggest problem in my program, Thank you!
@user-dt8ei1wj2x
@user-dt8ei1wj2x Жыл бұрын
Thank you Tim!! Really helpful
@user-gt9uw7ec6z
@user-gt9uw7ec6z 4 жыл бұрын
Thank you! Very well explained! Understood you much better than literature on my native language
@letslearnabout4934
@letslearnabout4934 4 жыл бұрын
Great video Tim. You need to make more threading and multiprocess videos.
@ophelia6207
@ophelia6207 3 жыл бұрын
Thanks so much, you're making it so easy to understand
@staticbits
@staticbits 4 жыл бұрын
Can't wait for the next video!
@akashkumarjain654
@akashkumarjain654 4 жыл бұрын
I am really thankful to you Sir for these informative videos on channel.
@San_desh24
@San_desh24 3 жыл бұрын
Bravo!! Ut theoretical and practical makes a lot clear
@GreenfieldPortfolioResearch
@GreenfieldPortfolioResearch Жыл бұрын
excellent content! straight to the point. enormously useful.
@venkatv4993
@venkatv4993 2 жыл бұрын
superb explanation understood something with this video after watching n number of other videos Great Tech with Tim always explains well in detail. thanks for teaching us
@mhho2336
@mhho2336 Жыл бұрын
Dude, your tutorial is awsome
@MiloLabradoodle
@MiloLabradoodle 3 жыл бұрын
Very nice presentation on this topic. Thanks so much.
@mbonuchinedu2420
@mbonuchinedu2420 4 жыл бұрын
Your coding is swift. Thanks Tim🥰💥💥💥
@yashpundir2044
@yashpundir2044 3 жыл бұрын
Just amazing... please bring out the next video soon.
@donaldhu2392
@donaldhu2392 3 жыл бұрын
Your video is Super Awesome!!! Thank you!!
@CodePhiles
@CodePhiles 4 жыл бұрын
great demonstration, Thanks , I would always use print from each thread to make it clear for me, like in thread #1 , you could print "I am coming from Thread #1" and for thread #2 , you could print "I am coming from Thread #2" and so on
@TahaCodes
@TahaCodes 4 жыл бұрын
Hey Tim, thanks for the great tutorial.
@davibus
@davibus 2 жыл бұрын
Great stuff. Thanks!
@dnetne5508
@dnetne5508 4 жыл бұрын
Wow.. I actually did not think you could explain things this well, not only in this video, but also in the last one... Big thanks from the heart!
@satanthegamer3969
@satanthegamer3969 2 жыл бұрын
really wish there were more of these!
@OmerMeshy
@OmerMeshy 3 жыл бұрын
Thank you very much! That video help me to solve a big problem in my code
@noahnolte7288
@noahnolte7288 3 жыл бұрын
Very helpful! Thanks!
@we_super_dooper
@we_super_dooper Жыл бұрын
great explantaion 👍👍👍
@karlchristiaens4673
@karlchristiaens4673 Жыл бұрын
Amazing! thank you
@link9645
@link9645 4 жыл бұрын
Thanks for the tutorial all could you possibly go over multithreaded socket programming later on in the series?
@TopBagon
@TopBagon 4 жыл бұрын
Nice one. Thanks a lot
@edzme
@edzme 3 жыл бұрын
Tim - you're a great teacher, love how you explain stuff and really break it down. 👍👍👍👍
@ak.pod31
@ak.pod31 4 жыл бұрын
Could you do multiprocessing as well after threading? Thank you!
@oldmankatan7383
@oldmankatan7383 2 жыл бұрын
For anyone else who finds this, the short answer is yes. The long answer is, you (usually) want to do your multiprocessing from __main__, and then if any of those processes require threading do the threading inside of that process. This is mostly due to the ways you get data out of threads (same process same heap) vs. processes (different process, different heap).
@F_M_911
@F_M_911 2 жыл бұрын
thank you very much💗
@quickdry3
@quickdry3 4 жыл бұрын
I know this might not be appropriate for the target audience, but a good explanation of the GIL, and what that means for threading in particular might be helpful to people expecting more parallel execution of their code (and why async approaches or multiprocessing might be more suitable).
@Dsuchong
@Dsuchong 2 жыл бұрын
well done!
@danieleperera6788
@danieleperera6788 4 жыл бұрын
Nice video! Keep up the good work! Do you mind doing some complicated examples where you use queues. Maybe a project like scraping the web to collect news feeds... something like that. With a real world example. Thanks a lot! Have a good one
@miguelalbertooxa8699
@miguelalbertooxa8699 4 жыл бұрын
ThNks Shelton!
@houssamhoussam2919
@houssamhoussam2919 4 жыл бұрын
thank you sir for you video very good waiting for new video :)
@richardravich8337
@richardravich8337 4 жыл бұрын
Great tutorial, Tim and I'm looking forward to the next one in the series. BTW, I noticed that you use both " and ' for strings. Shouldn't a programmer standardize on one? I know they are equivalent, but just for ease, shouldn't you standardize on one? Just curious...
@ikbenmathijs9424
@ikbenmathijs9424 4 жыл бұрын
I didn't even notice lol
@qazqaz2912
@qazqaz2912 3 жыл бұрын
Wanna push like button but four 6 in a row under this video don't let me do it :)) p.s. Amazing video! Big thanks!
@tjpeterson44
@tjpeterson44 4 жыл бұрын
Excellent guide Tim! Just one question, how do you return a value from a thread and use it in the main thread?
@haaziquesayyed5473
@haaziquesayyed5473 3 жыл бұрын
hey pls continue this series
@bechararizk7245
@bechararizk7245 4 жыл бұрын
hey just asking when will the next video about threading come out? thanks a lot for doing these tutorials
@oyoplayer
@oyoplayer 3 жыл бұрын
Thank !
@MrWaimanu
@MrWaimanu 2 жыл бұрын
Hi Tim. Really enjoying the tutorials. Would it be possible for a new threading video that covers the type of actions a function might do that would cause the cpu to switch threads? In the example you have time.sleep(), but in practise I'm unsure what other types of functions/actions would result in the program jumping between threads.
@psharma2067
@psharma2067 4 жыл бұрын
Perfect
@ronen124
@ronen124 2 жыл бұрын
you are the best
@krishj8011
@krishj8011 4 жыл бұрын
awesome....
@joshuakoehler6457
@joshuakoehler6457 3 жыл бұрын
Is there a third video coming out for this? I don't see it in the playlist...
@Chaosman88
@Chaosman88 3 жыл бұрын
I guess the third part never came.. Would be good though.
@BT-kf4kx
@BT-kf4kx Жыл бұрын
There will be lots more coming I hope 🤞
@arpitdiwan4573
@arpitdiwan4573 3 жыл бұрын
thanks you
@Aadyagupta5679
@Aadyagupta5679 3 жыл бұрын
please cover all topic related to multiprocessing and multithreading
@sprototles
@sprototles 2 жыл бұрын
Moooore !!!!
@dmbrv
@dmbrv 4 жыл бұрын
nice video
@MohamedHassan-zi7ms
@MohamedHassan-zi7ms 2 жыл бұрын
Greeeaaaaaaaaaaaaat :)
@domasvaitmonas8814
@domasvaitmonas8814 3 жыл бұрын
Amazing. Thanks a lot! I hope you can produce another vid on multithreading. Loved this one. By the way -- I wanted to donate to you via Brave browser, but couldn't. If you register, I could donate ;)
@HuyNguyen-fp7oz
@HuyNguyen-fp7oz 4 жыл бұрын
first! After 3 try, finally got it.
@TechWithTim
@TechWithTim 4 жыл бұрын
Yep! Finally lol
@HuyNguyen-fp7oz
@HuyNguyen-fp7oz 4 жыл бұрын
@@TechWithTim Keep good work, Tim. I learn alot from your videos!
@rahultiwari55
@rahultiwari55 3 жыл бұрын
I noticed that you somehow missed to use function count2 in the flow. That's why it got confusing.
@TheEbbemonster
@TheEbbemonster 3 жыл бұрын
Any part 3 in the pipeline? I have been doing to threading in a project, but ended up having trouble saving the outputs, as they wrote over each other :(
@ue5dev617
@ue5dev617 4 жыл бұрын
Will you talk about Semaphores ?
@jmsolorzano13
@jmsolorzano13 Жыл бұрын
Hi Tim! Excellent video... I can development an ashyncronate Application. But when I deploy in my docker container... not working.. :( Do you Know, if I need some special config to docker flask app with threading?
@julesuntalan9159
@julesuntalan9159 3 жыл бұрын
Hi, I'm new to python and currently learning from scratch. I have this project to automate a system using webdriver & selenium and at the same time, I need to create a screen recording using cv2. My problem is when I apply this threading, the flow of my code is that once automation was done it will execute the screen recording in which I need to do this at the same time. Hope you can help me with this project. Thank you!
@eddyhe
@eddyhe 4 ай бұрын
In the example, do the threads stop running after ls is printed? or do the threads continue to run after the print, but we want to see the ls with all of the elements appended to it so we have the .joins
@archibaldaddelton4432
@archibaldaddelton4432 4 жыл бұрын
in somenext tutorial I hope you get to using variable of thread "x" inside thread "y"
@relaxingwithmidfulmoment1177
@relaxingwithmidfulmoment1177 2 жыл бұрын
Tim how to pause and resume a thread ? Thanks man
@IND_Abhi
@IND_Abhi 4 жыл бұрын
which keyboard do you use?
@EK-ck2xf
@EK-ck2xf 4 жыл бұрын
Are you sure print('ran') will be executed as you've predicted? Isn't It possible that the last line in the code will be executed before? What does the python specification tells about running threads concurrently?
@PGhai
@PGhai 3 жыл бұрын
What is the logic of using _ in for loop? Could you plz explain or share some reference link?
@codewithkeshav6931
@codewithkeshav6931 3 жыл бұрын
How your sublime text editor gives preference of keywords. Would you tell the settings
@jakubcaputa9265
@jakubcaputa9265 4 жыл бұрын
11:42 You can try time.sleep(5) you sleep the main thread for 5 seconds and then you get desired output.
@adamgy
@adamgy 3 жыл бұрын
You could get away with that here, but in practical scenarios you won't know how much time the other threads take, so it's better to use join.
@muni3131
@muni3131 3 жыл бұрын
Thank. I’m wondering if multitasking will solve a problem I have but so far I can’t see a solution. Briefly, I have a window on which a function is running and it’s changing a lot of data on that screen. Then there is a pause button that needs to pause the process. I believe it must be possible; surely it’s normal to have start, stop, pause buttons on a window, but threads don’t seem to be allowed to interact with the same window especially were one thread is doing a lot of window updating. Does that make sense or am I barking up the wrong tree?
@beingraja9586
@beingraja9586 4 жыл бұрын
Good plZ try neural nets
@cicadaislive9988
@cicadaislive9988 4 жыл бұрын
make more video on these
@bartek9167
@bartek9167 4 жыл бұрын
How do you spawn new thread without assigning variable to it? (Or automatically assigning variable)
@arjunvarma2743
@arjunvarma2743 4 жыл бұрын
Much better😂
@hasibislam4421
@hasibislam4421 3 жыл бұрын
AttributeError: partially initialized module 'threading' has no attribute 'Thread' (most likely due to a circular import).....What does this mean?
@jayeshkawli
@jayeshkawli 3 жыл бұрын
Is there any way to view all the running threads in Pycharm?
@lightblue6746
@lightblue6746 4 жыл бұрын
11:25 Both of your threads(x and y) are targeted to function count. Is this what you meant or was it your fault??
@panzorax.
@panzorax. 4 жыл бұрын
Hi bro I have question this threads how can use in pyqt5 when I click button ?? Can you show us a example?
@JonDoe-uy9kn
@JonDoe-uy9kn 4 жыл бұрын
Hey Tim, being following you for a while and most say you sir are doing a great job! Is there any we to contact you ?
@ikbenmathijs9424
@ikbenmathijs9424 4 жыл бұрын
you can join his discord
@shibainu9969
@shibainu9969 Жыл бұрын
GOAT
@peterkim9696
@peterkim9696 Жыл бұрын
please help I have a txt file the contains urls to scrape something in each url and print result but whenever I add threads i see that requests prints duplicate results how can I solve that
@victordvickie
@victordvickie 4 жыл бұрын
🖤
@user-tq7re9mi5t
@user-tq7re9mi5t 4 жыл бұрын
why we need count2 when you never run it after 10:09 ?
@azurnxo2134
@azurnxo2134 4 жыл бұрын
Tim, What is your main programming language? I'm about to start with my first programming language, although I know python. What should I really start with? Please enlighten me. Thanks in advance.
@007MrNiko
@007MrNiko 4 жыл бұрын
Same question... @Tim
@feliperocha6521
@feliperocha6521 4 жыл бұрын
"I'm about to start with my first programming language, although I know python" I wonder what you think python is. Not gonna lie, it actually got me laughing.
@azurnxo2134
@azurnxo2134 4 жыл бұрын
@@feliperocha6521 bruhh
@azurnxo2134
@azurnxo2134 4 жыл бұрын
@@feliperocha6521 python is like a spoon fed to the software devs. I know it's amazing, but it's laughable at the same time. You need to know a deeper programming language to become more aware of your machine. For example, C++ makes you really aware of your machine and it's operations. Java, on the other hand derives its traits from C++, but it still is not as powerful as C++. C#, one of best programming languages out there, gets you covered in every aspect of software developing.
@VerifyBot
@VerifyBot 4 жыл бұрын
@@azurnxo2134 i disagree.
@__epicgaming__3492
@__epicgaming__3492 3 жыл бұрын
4:20 For me it prints the number first, and then "ran", and "done"
@venkyman4985
@venkyman4985 3 жыл бұрын
6:30 how is 2 printed on same line as run?
@cuthbertmilligen
@cuthbertmilligen 3 жыл бұрын
I think you probably wanted the y-thread to use count2. But as count and count2 are identical it makes no difference. So why create count2?
@premgarg5534
@premgarg5534 3 жыл бұрын
Hi, i have a query I want a python script to run at boot time but not the whole program just one thread, SO can anyone please help me it that
Python Asynchronous Programming - AsyncIO & Async/Await
25:57
Tech With Tim
Рет қаралды 414 М.
Which one is the best? #katebrush #shorts
00:12
Kate Brush
Рет қаралды 22 МЛН
WHO DO I LOVE MOST?
00:22
dednahype
Рет қаралды 50 МЛН
Khóa ly biệt
01:00
Đào Nguyễn Ánh - Hữu Hưng
Рет қаралды 11 МЛН
Python Tutorial: if __name__ == '__main__'
8:43
Corey Schafer
Рет қаралды 2 МЛН
Python Socket Programming Tutorial
49:43
Tech With Tim
Рет қаралды 1 МЛН
Locking & Synchronizing Threads in Python
10:18
NeuralNine
Рет қаралды 17 М.
PLEASE Use These 5 Python Decorators
20:12
Tech With Tim
Рет қаралды 96 М.
threading vs multiprocessing in python
22:31
Dave's Space
Рет қаралды 560 М.
5 Good Python Habits
17:35
Indently
Рет қаралды 372 М.
Unlocking your CPU cores in Python (multiprocessing)
12:16
mCoding
Рет қаралды 293 М.
Python dataclasses will save you HOURS, also featuring attrs
8:50
Python 101: Learn the 5 Must-Know Concepts
20:00
Tech With Tim
Рет қаралды 1 МЛН