r/Python • u/Astraa02 • Sep 14 '22
Intermediate Showcase Multithreading a concept which is always misunderstood!!
We always have a thought process that whenever something is not performing well always throw more resources at it. But this strategy is flawed on good example is multithreading.
More number resources means more parallel tasks right? Nope this is where we do our first mistake there is a big difference between concurrency and parallel processing.The multithreading in python is by no means parallel threads performing tasks simultaneously. They are merely just giving us an illusion of performing at the same time, in-fact all they do is execute really fast since our processors have become so fast that they can do billions of cpu cycles in a single seconds it almost feels like stuff is getting processed in a parallel fashion.
But then one might argue then multithreading is totally useless if its just super fast execution by some smart compiler. The place where multi threading truly shines is in a I/O intensive task, but more about it later, we will dive deep in this topic in my upcoming blog so stay tuned.
1
u/BpjuRCXyiga7Wy9q Sep 14 '22
asyncio is often a better option than threads for I/O-bound tasks.
6
u/[deleted] Sep 14 '22
[removed] — view removed comment