4 ms·
Do actual pythonistas really hate the GIL? I thought it was mostly a troll talking point, just like the whitespace.
by lmm 14y ago
Do actual pythonistas really hate the GIL? I thought it was mostly a troll talking point, just like the whitespace.
- jforman 14y agoWhy would the inability to write multi-threaded programs that are worth a damn be a troll talking point? It meaningfully lowers the appropriateness of using python for server code.
- nakkiel 14y agoThere's more than one way to do it. If you're thinking about hundreds of threads doing chunks of work, then my comment will not be meaningful but if you're talking about maximizing CPU utilization for a particular task, then multiple processes is a valid and proven approach (Tornado does just that for example, forking as many processes as you have CPUs and putting them to work).
- jedbrown 14y agoThe viability of separate processes is highly dependent on the problem domain and algorithm. Threads have their place.
- gaius 14y agoNo, the GIL is simply not relevant for real work. True Pythonistas, when performance is critical, just drop into C for the crucial section and use Python to control it. When C code is running, the Python runtime isn't blocked - you can kick off a hundred native pthreads in the background if you want to. This is also true in OCaml BTW, but it's trickier to make the call as when running single-threaded, OCaml code is as fast as C anyway. A Python/OCaml hybrid using C as glue is probably the best of both worlds.
- tetha 14y agoor you look at multiprocessing, which spreads the computation into multiple processes, while enforcing clear boundaries and communication methods.
- anacrolix 14y agoIt's becoming a problem. Even if your code isn't CPU bound, the GIL causes terrible scheduling problems.
- rogerbinns 14y agoThe main problem is the perception that code would linearly scale if the GIL was removed. Eg on a 4 core machine code would run 4 times as fast. And that the GIL has no value. Both statements are completely false. (A bigger issue is the reference counting anyway. Changing that should be a precursor to GIL removal.) I'm an author of a C extension (apsw) and the GIL is fantastic. Without it the code would be considerably more complicated, longer and likely to have race conditions and similar gnarly bugs. As a Python developer I use: * Multiple processes usually by executing a new process which allows me to easily substitute testing processes and using stdin/stdout * Use networking for talking between parts (allows spreading over multiple machines, failover, redundancy, load balancing etc) * multiprocessing for pure Python work * Threads for I/O bound work or work that waits on other things * C extensions that release the GIL Actually getting rid of the GIL wouldn't help.