I just killed GIL!!!

"Martin v. Löwis" martin at v.loewis.de
Thu Apr 17 17:01:45 EDT 2008


> An there you have the answer. It's really very simple :-)

I'm fairly skeptical that it actually works. If the different
Python interpreters all import the same extension module
(say, _socket.pyd), windows won't load the DLL twice, but
only one time. So you end up with a single copy of _socket,
which will have a single copy of socket.error, socket.socket,
and so on.

The single copy of socket.error will inherit from one specific
copy of IOError. So if you import socket in a different
interpreter, and raise socket.error there, and try to catch
IOError, the exception won't be caught - because *that*
IOError is then not a base class of socket.error.

A more general approach similar to this one is known
as ".NET appdomains" or "Java isolates". It requires
the VM to refrain from having any global state, and
to associate all "global" state with the appdomain
or isolate. Python can't easily support that kind of
model, because extension modules have global state
all the time.

Even if Python supported appdomains, you still wouldn't
get any object sharing out of it. As soon as you start
to share some object (but not their types), your entire
type hierarchy gets messed up.

FWIW, Tcl implements this model precisely: Tcl is
not thread-safe in itself, but supports a
interpreter-per-thread model. I'm also skeptical that
this is any better than the GIL.

Regards,
Martin



More information about the Python-list mailing list