A problem in embedding Python in a plug-in

K

Koichi

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.

Koichi
 
G

Gabriel Genellina

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

Given all those constraints, I think the only safe option is to run
Python in another process.
You write a very simple plugin (NOT in Python, maybe C code) that
spawns another process (the actual Python code) and forwards all
requests to that other process, using some form of IPC.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,226
Members
46,815
Latest member
treekmostly22

Latest Threads

Top