The GIL is controversial because it prevents multithreaded CPython programs from taking full advantage of multiprocessor systems in certain situations. Note that potentially blocking or long-running operations, such as I/O, image processing, and NumPy number crunching, happen outside the GIL. Therefore it is only in multithreaded programs that spend a lot of time inside the GIL, interpreting CPython bytecode, that the GIL becomes a bottleneck.
Is not that the threads compete over the GIL, it's just that they aren't locking the same objects to begin with. So a new thread can participate in the IO process when another blocks.
Yes, knowing what your code is doing is the key to figuring out whether and how much you'll be affected by the GIL.
(and yes, it's mainly an issue for multi-threaded CPU-bound applications; IO-bound applications feel it much less, if at all compared to the normal overhead of the language)
17
u/oconnor663 Nov 20 '15 edited Nov 20 '15
This depends on whether your code is CPU-bound or IO-bound, right? Don't Python threats release the GIL before they wait on network reads and stuff?
Edit: Found what I was looking for: