[Python-Dev] Global interpreter lock/import mechanism
Joerg Budischewski
JoergBudi@gmx.de
Thu, 30 Jan 2003 15:08:15 +0100
Hi,
I am one of the authors of the python binding for the OpenOffice'
component model UNO( see http://www.openoffice.org and
http://www.budischewski.com/pyuno/python-bridge.html).
First of all, let me say, that is real fun to work with python C API and
its documentation.
However, there are still some open questions, for which I haven't found
an answer in the documentation.
1) I can't find an API call to get to know, whether the current thread
has the global interpreter lock or not. ( A recursive lock would also help).
Some background: UNO objects are also reference counted, when they get
destructed, they may need to PY_DECREF python references. However, the
OpenOffice object's dtor might either be called with or without global
interpreter lock.
I currently workaround this by delegating the PY_DECREF to a new thread,
however, which has the defined state (it does not have the lock, so it
must acquire it), but this is quite inefficient.
2) I would like to hook into the python import mechanism in order to
introduce new classes. I currently do this by replacing the
__builtin__.__dict__["__import__"] with my own version, which delegates
to the original function and in case of failure tries to lookup a UNO type.
This allows e.g. by writing
from com.sun.star.uno import XComponent
to elegantly create such UNO types.
However, I think, the replace-__import__-function is quite a nasty
solution, I would rather like to have an API for this. Is there an API I
have overlooked (or is it planned to have something like that ? ).
3) The Python-UNO bridge can be used within the python process or within
the office process itself ( so called UNO components). For the latter,
the binding initializes python by calling Py_Initialize().
As you might know, OpenOffice.org comes as a binary (not in source) even
on unix platforms. But I don't want to decide at buildtime, which Python
version the user should use (and actually I don't want to ship python),
instead I want to reuse a python version, which already exists on the
system.
But currently, the python unix buildprocess does not create a shared
library, only a static lib (while on windows a shared library gets built).
Are there any plans to add also a shared libs for unix ?
Thx in advance,
Joerg