Jython, GILs and object locking.
Harri Pesonen
fuerte at sci.fi
Thu Oct 16 15:50:14 EDT 2003
Daniel Dittmar wrote:
> Harri Pesonen wrote:
>
>> You are probably asking next "how threads can communicate". They can
>> communicate with messages, and via special shared interpreter state,
>> which needs a new "shared" keyword in python. Access to these shared
>> variables is synchronized, all other variables are local to thread,
>> and they need not be synchronized.
>
> So you're not talking about Python threads in the meaning of the module
> 'thread'. Instead you want to be able to create multiple interpreters in
> the same process and run them in parallel via threads. Today, the Global
> in GIL is really global instead of interpreter local.
Exactly. But Viper (my free-threading Python) will have something
similar to 'thread' modules as well, maybe I call it 'freethreading'.
Thread created by this module will also have independent interpreters.
They can communicate with the above methods, but their other variables
are local.
> I'm not saying that this isn't a worthy goal. Server applications with
> embedded Python interpreters would profit from it and it is not that
> difficult to implement. (Although keeping the patches current with
> Python development will be awful as adding the interpreter state will
> affect every call at the C level).
I have a Python script that does the conversion. It already handles the
following static objects:
Py_None, Py_NotImplemented, Py_Ellipsis, Py_False, Py_True
Next I will add the thread state argument to every function that needs it.
> I could even imagine that extension methods get an addditional flag that
> signals that this methods is able to run in the GIL free environment.
> Older extensions don't have that flag, so Python has to suspend all
> other threads while this extension is running. This is perhaps a way to
> achieve backwards compatibility.
Perhaps, the backwards compatibility is not my top priority. Making
Python free-threading is. I embedded Python into multithreading web
server, and found out that it is not ideal for the job.
Harri
More information about the Python-list
mailing list