5 ms·
> Sadly, that's not practically possible. Why? With cpython there are plenty of cases where parallelism is possible with threads because the GIL is released (f
by nicolaslem 8y ago
> Sadly, that's not practically possible.
Why? With cpython there are plenty of cases where parallelism is possible with threads because the GIL is released (for instance most IO operations and many C based number crunching operations), making threads and locks useful.
- heavenlyblue 8y agoSo technically if you wrote most of your number-crunching code as a C module for python, then you could use threads... Can't you see a problem here?
- chrisseaton 8y agoNo you can still use pure Python, and use multiple threads, and get concurrency just fine. The global lock doesn't stop you doing that! C extensions being able to release the lock is just a bonus on top.
- dagw 8y agoIf you don't want to use C (I don't blame you if you don't) you could use Cython or Numba. And certainly in my number crunching code the amount of code that actually crunches numbers, and thus could really benefit from being written in a GIL releasing way, is really quite small.
- objectified 8y agoLots of problems are merely I/O related, which can be solved just fine with Python threads. As for number crunching (let's assume that means CPU intensive tasks), you can always still resort to multiprocessing (which can also be combined with multithreading, I fail to see why such paradigms cannot be combined).
- heavenlyblue 8y agoWell, io-related problems can be solved even better by using gevent. The io-related problems I had with paramiko, on the other hand - last time I checked could neither be solved with threads or gevent. So that’s a weak point to be made anyway.
- amelius 8y agoYes, but it's very easy to hit a number crunching operation that locks the GIL.