I'm interested in whether psyco can be used to solve
one of the biggest problems with python's
multithreading support: that the interpreter is not
re-entrant, so it is difficult for one thread to
interrupt another, and on multiprocessor machines only
one thread may execute at once.
Does psyco currently unlock the interpreter while
compiled code is being executed (I've had a quick look
at the code in CVS and it seems it doesn't, although
I'll admit that I'm pretty certain I haven't found all
the places it could happen)?
If it doesn't, is it feasible to add such a feature?
It would seem that the feature should be an
off-by-default option (as it will almost certainly
reduce performance on single processor machines), and
that it should be avoided wherever the interpreter is
likely to make a call back into the Python environment
in the near future (this would seem to make the feature
non-trivial to implement, otherwise I'd have downloaded
the code and figured out what to change to do it myself).
Logged In: YES
user_id=4771
This is a good idea, though I don't see a reasonable way to
implement it in Psyco. Most sequences of generated code
have to run with the GIL (Global Interpreter Lock) acquired,
even those with no explicit call to the C API -- for example,
reading a list item is inlined and only takes a few assembler
instructions, but these have to be protected by the GIL too
or they could read garbage or segfault if the list is modified at
the wrong time by another thread. The only kind of code
that could run without the GIL is really purely arithmetic code,
and even so the GIL is needed from time to time due to
limitations of Psyco (e.g. each 'return some_int' forces a call
to PyInt_FromLong()).