0

Theory:

  1. Single CPU can execute one process at a time. Also thread is light weight process. It means CPU can execute one thread at a time.

  2. As mentioned here

    CPython implementation detail: In CPython, due to the Global Interpreter Lock, only one thread can execute Python code at once (even though certain performance-oriented libraries might overcome this limitation). If you want your application to make better use of the computational resources of multi-core machines, you are advised to use multiprocessing. However, threading is still an appropriate model if you want to run multiple I/O-bound tasks simultaneously.

Questions:

  1. Why do we blame global interpreter lock of python, if one thread can execute one time at CPU level itself ?
  2. Python thread is Kernel or User level thread ?
  3. I/O bound tasks still involve CPU, right ? How I/O affects to threading, does it really affect ?

My understanding to (1st question):

Single CPU: Global interpreter lock doesn't matter.

Multi Core CPU: In multi core CPU, we won't be able to take advantages of thread because of global interpreter lock.

Does it mean we can achieve parallel processing in Multi Core CPU ?

Is my above understanding to 1st question correct ? Also what will be the answers to other questions ?


P.S: After reading above question you must have got that my understanding with respect to (multi)threading/(multi)processing/multitasking/ of OS vs Python is not connected properly. I just asked this question so that I can connect the dots. It will be really appreciated if you can provide any link/blog/book which can make understanding correct.

Anurag
  • 1,013
  • 11
  • 30
  • 2
    Your question is really too broad; keep it focused to one specific aspect please. I've duped you to a question that answers a large section of your questions. – Martijn Pieters Jan 12 '16 at 10:08
  • 2
    Python uses native threads, not 'green' threads. Python is a user-space program, not a kernel component, so it is unclear what you mean by kernel vs. user-level threads. I am assuming you mean native vs. green (lightweight) threads. See [Difference between user-level and kernel-supported threads?](http://stackoverflow.com/q/15983872) – Martijn Pieters Jan 12 '16 at 10:09
  • 1
    From my understanding the disadvantage happens with multicore CPUs. IO bound tasks like file read, or downloads are implemented in the Python standard library in a way that it frees the GIL, so you can achieve real parallel processing. For other situations you would have to use multiprocessing instead of threads. – dyeray Jan 12 '16 at 10:17

0 Answers0