A problem in embedding Python in a plug-in
kotamura at hello.email.ne.jp
Sat Jan 6 19:29:41 CET 2007
Hi, I'm now making a plug-in for a CG software. I embed
Python in a plugin and it works. The problem is that it
conflicts with other plugins that also embeds Python because it
runs in the same thread. I don't know when Py_Initialize() and
Py_Finalize() are executed because I don't know when user loads/unloads
a plugin that embeds Python. Is there any right way to embed
Python in a plug-in under the following conditions? If not, what
options do I have to give up any of them?
- My plug-in has no way to know when the user loads/unloads it.
- My plug-in has no way to know when the user loads/unloads somebody
else's plug-in that embeds Python.
- Somebody else's plug-in might have used any Python/C API including
GIL related stuff, new_interpreter, PyGILState_*
- Every plug-in initially runs in the same thread but some plug-in
can start a new thread.
- Preferably my plug-in has its own __main__
- My plug-in doesn't have to be thread safe but shouldn't disturb
any other plug-in (so should be thread safe anyway)
Typical problem is:
- When somebody else loads or unloads another plugin and calls
Py_IsInitialized() or Py_Finalize(), my plugin fails
- When some other plugin uses PyGILState*(), both plugin fails
because my plug-in uses new interpreter
(I'm new to Python/C API so I may be misunderstanding one ore more)
Any suggestion is appreciated.
More information about the Python-list