So Pythonistas, you want to get rid of the GIL...
functional-orbitz.blogspot.se
functional-orbitz.blogspot.se
I suppose a problem is that unlike Java, Python is not fast enough to implement low level data structures in the language itself, so you can't easily implement non-thread-safe data structures without losing memory safety at the C level, which is unacceptable.
Still, I have the feeling that with heavy use of biased locking, you could stick locks everywhere without a lot of overhead in the non-contended case. Or maybe that famous patch just needs to be revisited, tweaked to more efficiently address the areas of highest contention... see http://dabeaz.blogspot.com/2011/08/inside-look-at-gil-remova... for some context.
(some forms of biased locking are patented.)
@jagw: ok fair, but that is going to be the very first example of things thou shalt not do when using threads in any article, book, or course
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.
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.
If I need performance badly enough that I'm considering making major structural changes in order to utilise multi-process or find some other way around the GIL, I probably ought to be considering using a language that supports what I'm trying to do. Of course my python projects tend to be fairly small.
Usually when I've hit this situation I'm writing something simple but processor intensive, and it's easier for me (12 years commercial parallel/distributed C programming, amateur python enthusiast) to go back to home ground at this point.
[1]: http://docs.python.org/py3k/library/concurrent.futures.html
Scala, Go, Clojure etc make this so much easier that I think a language jump is reasonable.
Often I have use-cases where my own shared memory system works well http://williamedwardscoder.tumblr.com/post/13363076806/buffc...
> I was writing a custom video editing program in Python (interesting choice of language for that problem) and I wanted to cache decoded frames
Apart from that I really like Python.
For this reason, I actually use QThread in console apps aswell.
if (obj.owner == current_thread):
# just get in and mess with it
elsif (obj.owner == shared):
# get in and mess with it under a lock
else
throw "not your obj - make this obj shared if you need that"
From a language perspective, you'd just need a way to declare that an object was 'shared'. All other objs would be owned by their creating thread.But Python is different than Java. The Python interpreter has to guard the internal data structures of the interpreter itself, and that is a lot more tricky than it seems on the surface.