How is Multithreading achieved in Python?

devquora
devquora

Posted On: Feb 22, 2018

 

 Python programming has a multi-threading package that can be used if one wants to multi-thread to speed their code up.

A construct called the Global Interpreter Lock (GIL) is available in Python. It is the work of the GIL to make sure that only one of the ‘threads’ can execute at any one point of time. Normally a thread accepts the GIL, does a little work, then passes it on the GIL to the next thread.  All this happens very quickly that will seem so to the human eye and 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.

    Related Questions

    Please Login or Register to leave a response.

    Related Questions

    Python Interview Questions

     How is Python different from Java?

    Java and Python are way different from each other, but both of them can be useful tools for high-tech developers. Also, ..

    Python Interview Questions

    How does exception handling in Python differ from Java?

    Python uses its own techniques to implement exception handling. <try-except> is the block that can be utilized by..

    Python Interview Questions

    What is a module and package in Python?

    Modules can be defined as the Python files with an extension “.py”. The module name will be same as that of the fil..