Multiprocessing and Parallelism in Python
Threading
What is threading in python?
A thread is a separate flow of execution. This means that your program will have two things happening at once. But for most Python 3 implementations the different threads do not actually execute at the same time: they merely appear to.
Achieving concurrent execution of multiple tasks necessitates employing a non-traditional Python implementation, incorporating code in an alternative language, or opting for multiprocessing, albeit with additional overhead.
Due to the way how CPython implementing Python work, not all tasks can be speeded up by threading. Only one python thread run at a time due to the essential limitation induced by the interation with the GIL.
Threads is compatible when tasks that spend much of their time wait for external events, whilst problems that require heavy CPU computation and spend little time waiting for extenral events might not run faster at all. in this case, multiprocessing module is approriate for these CPU-bound problem.
Architecting your program to use threading can also provide gains in design clarity. Most of the examples you’ll learn about in this tutorial are not necessarily going to run faster because they use threads. Using threading in them helps to make the design cleaner and easier to reason about.
Launching a Thread
Multiprocessing and Parallelism in Python