Using PyGILState_Ensure

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Ralf Riemer

    #1

    Using PyGILState_Ensure

    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.[color=blue]
    >From Python I call a function from a C++ dll using[/color]
    calldll.call_fo reign_function. This C++ function does a callback of a python
    function.
    Do get it running I use PyGILState_Ensu re before PyEval_CallObje ct and
    PyGILState_Rele ase 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_STAT E gstate;
    //Ensure that the current thread is ready to call
    the Python C API
    gstate = PyGILState_Ensu re();

    ppyobjResult = PyEval_CallObje ct(my_callback,
    ppyobjArgList);
    if (!((DWORD_PTR)p pyobjResult))
    {
    //Error handling
    ...
    } else {
    Py_DECREF(ppyob jResult);
    }

    Py_DECREF(ppyob jArgList);

    PyGILState_Rele ase(gstate);

    Now my questions:
    Are there any risks aquiring the global interpreter lock?
    Do I invoke by PyEval_CallObje ct a new python process? (I suppose not)
    How long my this call of PyEval_CallObje ct 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

    --
    Lust, ein paar Euro nebenbei zu verdienen? Ohne Kosten, ohne Risiko!
    Satte Provisionen für GMX Partner: http://www.gmx.net/de/go/partner
Working...