Python Developer Question:

Do you know how is Multithreading achieved in Python?

Tweet Share WhatsApp

Answer:

☛ Python has a multi-threading package but if you want to multi-thread to speed your code up.
☛ Python has a construct called the Global Interpreter Lock (GIL). The GIL makes sure that only one of your ‘threads’ can execute at any one time. A thread acquires the GIL, does a little work, then passes the GIL onto the next thread.
☛ This happens very quickly so to the human eye it may seem like your threads are executing in parallel, but they are really just taking turns using the same CPU core.
☛ All this GIL passing adds overhead to execution. This means that if you want to make your code run faster then using the threading package often isn’t a good idea.

Download Python Developer PDF Read All 77 Python Developer Questions
Previous QuestionNext Question
Suppose ou are having multiple Memcache servers running Python, in which one of the memcacher server fails, and it has your data, will it ever try to get key data from that one failed server?Tell me what Flask is and its benefits?