By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,846 Members | 1,857 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,846 IT Pros & Developers. It's quick & easy.

A problem in embedding Python in a plug-in

P: n/a
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
Jan 6 '07 #1
Share this Question
Share on Google+
1 Reply


P: n/a
On 6 ene, 15:29, Koichi <kotam...@hello.email.ne.jpwrote:
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.

--
Gabriel Genellina

Jan 7 '07 #2

This discussion thread is closed

Replies have been disabled for this discussion.