Using PyGILState_Ensure

R

Ralf Riemer

Hi,

I have some questions concerning the global interpreter lock:

I am working with Windows XP Professional Version 5.1, Python version 2.4.1
and Microsoft Visual C++.Net Version 7.1.
From Python I call a function from a C++ dll using
calldll.call_foreign_function. This C++ function does a callback of a python
function.
Do get it running I use PyGILState_Ensure before PyEval_CallObject and
PyGILState_Release afterwards.
The code looks like this:

static PyObject *my_callback = NULL;

...

// my_callback is set from Python using a function SetCallback
...


/* Time to call the callback */
ppyobjArgList = Py_BuildValue("()", NULL);

//General Interpreter Lock (essential for succesful
calling of any python function)
PyGILState_STATE gstate;
//Ensure that the current thread is ready to call
the Python C API
gstate = PyGILState_Ensure();

ppyobjResult = PyEval_CallObject(my_callback,
ppyobjArgList);
if (!((DWORD_PTR)ppyobjResult))
{
//Error handling
...
} else {
Py_DECREF(ppyobjResult);
}

Py_DECREF(ppyobjArgList);

PyGILState_Release(gstate);

Now my questions:
Are there any risks aquiring the global interpreter lock?
Do I invoke by PyEval_CallObject a new python process? (I suppose not)
How long my this call of PyEval_CallObject last? Are there restictions to
the code I use in the called function.
Is it allowed to force the thread to wait (by aquiring the GIL)?
Is there a risk that windows hangs up?
Doing several calls of my dll function with the callback, is there a risk
that the calls overlap and information gets lost?

Thanks for your help!
Ralf
 

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,769
Messages
2,569,582
Members
45,070
Latest member
BiogenixGummies

Latest Threads

Top