Let's Learn Python #22 - Multithreading

Let's Learn Python #22 - Multithreading
This week, I cover the basics of Multithreading and a simple implementation of it in Python!

Please leave me a comment or question below! Like and Subscribe to show your support! :D


Editor = SUBLIME TEXT 2: http://www.sublimetext.com/2

Multithreading Interview Q & A #1 & #2:  


Multithreading Lock and Join Documentation:




Music by Juto: Link Coming Soon!

---     SUPER TUTORIAL LIST!!!    ---

LLP #25 - UI with PyQt & OpenGL - http://youtu.be/eJveTXSXs8Q
LLP #24 - UI with Python, PyQt & Qt Designer - http://youtu.be/GLqrzLIIW2E
LLP #23 - Regular Expressions - http://youtu.be/ZdDOauFIDkw
LLP #22 - Multithreading - http://youtu.be/i1SW4q9yUEs
LLP #21 - Min Max Algorithm - http://youtu.be/fInYh90YMJU
LLP #20 - A* Algorithm - http://youtu.be/ob4faIum4kQ
LLP #19 - Finite-State Machines (FSM) - http://youtu.be/E45v2dD3IQU
LLP #18 - Factory and @classmethod - http://youtu.be/flOXIdWUpmU
LLP #17 - Type Class Creation, Metaclass - http://youtu.be/pd4Lm_WLJpM
LLP #16 - Singletons - http://youtu.be/6IV_FYx6MQA
LLP #15 - Nesting Functions and Decorators - http://youtu.be/fVon4QaY4wo
LLP #14 - *Args, **Kwargs - http://youtu.be/WWm5DxTzLuk
LLP #13 - UML - Unified Modeling Language - http://youtu.be/U3B5z2HQlaQ
LLP #12 - Abstract Classes, Multiple Inheritance - OOP 3 of 3 - http://youtu.be/rOaRMW8jYOo
LLP #11 - Overriding & File Mng. - OOP 2 of 3 - http://youtu.be/TF_y8Gta0vY
LLP #10 - Inheritance - OOP 1 of 3 - http://youtu.be/pxbdnrjf-Uc
LLP #9 - Creating Text Files - http://youtu.be/DRZdfd5_rdg
LLP #8 of 8 - Classes - http://youtu.be/trOZBgZ8F_c
LLP #7 of 8 - Files and User Input - http://youtu.be/0ury8KHQdL4
LLP #6 of 8 - Functions - http://youtu.be/qO4ZN5uZSVg
LLP #5 - Exception Handling - http://youtu.be/hrR0WrQMhSs
LLP #4 - Loops - http://youtu.be/6HWK6O4-28E
LLP #3 - Conditionals, If, Else, Elif - http://youtu.be/mQrci1kAwh4
LLP #2 - Strings, Lists, Tuples and Dictionaries - http://youtu.be/19EfbO5D_8s
LLP #1 - Integers, Floats and Maths - http://youtu.be/D48iCw3WWpI


BASICS - https://www.youtube.com/playlist?list=PL82YdDfxhWsDJTq5f0Ae7M7yGcA26wevJ
OBJECT ORIENTED PROGRAMMING - https://www.youtube.com/playlist?list=PL82YdDfxhWsAyY3iNNDC1kUKWAJibUGi6
SCRIPTING PLAYLIST - https://www.youtube.com/playlist?list=PL82YdDfxhWsC-3kdTKK2_mwbNdBfVvb_M


RRelated Posts

APIs | REST | REST APIs Demystified

Hey fellow developers! In this video, I tried to explain in details what an API is? How does it relate to web service? How does it relate to REST? I also explain REST (REpresentational State

Understanding the Python GIL

Dave Beazley's presentation from PyCon'2010 in Atlanta Georgia. This is a mirror of the original presentation hosted at


  • Arsenius
    In the second example why is q = queue.Queue(10) It seems the 10 means to do the job 10 times. but that has no practical use. if have list with items that need to be processed. how do you make it put the items in a queue?
  • 杨之昊
    10:22 do you mean a bit faster? How is adding double the amount makes consumer slower?
  • prefertoxic
    This tutorial helped me a lot, thank you!
  • Estefanía M
    Very clear, thanks a lot!! One question I have: if one of the classes should be a window (for example using Tkinter if possible), what to put inside de definition of 'def run(self): ¿?'
  • Akshay Anand
    nice and clear explanation.
  • Diptarko Das Sarma
    Thanks a lot. However, getting error with the time.clock() calls, getting following error : AttributeError: 'float' object has no attribute 'clock'. Am stuck. Please help
  • rajesh shrestha
    thanks man this video helped alot
  • tim elgr
    It was awesome.Do you have a link to download the second example ?
  • The Trash Wizards
    Thank you T-Pain
  • Dexter Injector
    I need code source
  • Stu Mashaal
    concurrency is not parallelism!
  • FreeFlamingInfinite
    So this is what T.Payne sounds like without the auto-tune and backing tracks.
  • Dayvie
    There is not a lot of multithreading in Python due to the global interpreter lock. You have to use multiprocessing for real parallelization in Python.
  • Wang Yanxuan
    You video is awesome!
  • Anna Brzozowska
    As for the Producer code, wouldn't it be a little more clear to simply use random.choice? Like this: f = random.choice(self.food)?
  • Patrick Hastings
    Great video, and likely the best among multiple videos. You knew what you were talking about, Trevor, and took the content to its threshold for introduction material.
  • jatin gupta
    when i am running the program only the thread of consumer is running and not of thread, please help ??
  • Igor Farias
    Very good! Thanks xD
  • Vishnu Ashok
    who draws all those drawings. they are awesome and funny af.
    hey good tutorial keep it up
  • Josef Lát
    will this overcome the raw_input() stop feature?

    other words - I need a loop to run nonstop, even if the 2nd part of code is waiting for an input.
  • Jason Bettineski
    Producer/Consumer was exactly the code sample I was looking for to get an example I could work off of with multiple classes on multiple threads. Thanks!
  • definty
    Wow, only 30 seconds in but you introduced this video like you are meant to when talking about Python. Which version are applicable!
  • Anugrah Vijay
    Perhaps it's also useful to mention processes and the difference between threads and process (I'm looking at you memory space) and talk a little about GIL lock when it comes to cpython multi threading. CPU intensive tasks simply may not benefit from multi threading while multiprocessing will work wonders.
  • Michal Monday
    thanks, I like the example with plates, you should be a pro teacher
  • Elvis Sun
    I was stuck on doing a multi-threaded bidirectional search, this really helped, thanks! :)
  • Samuel George
    It is spelled "sentence" not "sentance"...
  • NotQuiteMelvin
  • Damilola Boiyelove
    Cool video, and comforting concepts with the jokes, can you do a multi-threading video on pysocket and pyclient. I'd love to see that
  • Shriram MC
    Great Video!! Simple and Well explained
  • Talha Tariq
  • locca1
    very useful
  • Nacanieli Tabua
    Hi T Payne,

    I want to implement a forward and inverse kinematics control algorithm on python on the raspberry pi......

    How would i probably go about doing that???.....Note that I have 5 inputs which is to be defined by the user.....

  • Shawn Chen
    Your video is so great
  • Adam Olsson
    These tutorials are just awesome. Really great job!
  • Luis III
    Hi, thank u some much, do you have a link for download the examples? Regards
  • amrosik
    I can run the second example only once. I have to restart the kernel, to rerun it.
  • javalin597
    Thank you so much!.........oh but........sentence
  • Passwordcracks
  • Niels Langeweg
    This was so clear. hopefully you will get more subs (200k) because je definetly* earn it!
  • SlackHax
    Please learn how this works before you spread more misinformation. You miss the whole concept of multicore, multi-programming, multithread programming and simultaneous multithreading. If you don't know how that words, just say: "Multithreading in python, is running multiple threads at the same time". Don't try to explain things you don't know or understand yourself. It's like listening to a toddler explain how hyperthreading in an i7 cpu causes micro-stuttering in their game... stupid things like this, is the reason most people don't know shit about computers. And when you try to explain things, they say: "But I thought it was blablabla, no this is too hard, why bother".
  • FreeTheCross
    I liked this tutorial
  • Gareth Welch
    I'm confused regarding the point of the function start(). Whenever I create a thread with t = threading.Thread(...), it runs the target funtion the moment that line of code is executed. When I run t.start(), absolutely nothing happens.
  • Igor Itkin
    Hey man, its great!
  • Manav Kataria
    0:46 Lets not confuse muti-threading and multi-programming. Running multiple programs within the same computer is multi-programming while performing multiple tasks within the same program via multiple threads is multi-threading (via multiple processes is multi-processing).

    Read more:
  • Boombaustic
    Holy shit im ready to subscribe just cause of how cool the outro was.
  • Lando Calrissian
    Wouldn't you be limited to only one core on the CPU because of GIL in python? Or did they change that in python 3?
  • AQUA4
    Wow, this was really helpful! It's great for setting intervals, I noticed. :)
  • Eigenfield Aparicio
    will it be possible for you to include tutorials on gevent in future time?