Extending embedded python of multiple interpreters

Discussion in 'Python' started by vishnu, Mar 31, 2007.

  1. vishnu

    vishnu Guest

    Hello All,

    I have embedded python 2.5 in to my C application. As we need the
    python scripts to run in multi threaded environment I have used
    Py_NewInterpreter() and Py_EndInterpreter each time I execute a run
    script function.
    The code is as follows:
    RunScript(char *pScriptName,char *pFuncName,...)
    {
    PyEval_AcquireLock()
    threadState = Py_NewInterpreter();
    PyThreadState_Swap(threadState);

    /* Import the script module and run the fnc in that script module */
    Pyobject *pModule = PyImport_Import(pScriptName);
    PyObject *pFunc = PyObject_GetAttrString(pModule, pFuncName);
    .....
    /* End running the script and calling the script fnc */
    Py_EndInterpreter(threadState);
    PyEval_ReleaseLock();
    }.

    And my python initialise looks as :
    pythonInit() {
    Py_initialise();
    PyEval_initThreads();//which enables multi thread support
    }

    Now I am extending the embedded python to expose my application
    library API's to python using SWIG. I written one extension module and
    from python i am setting the C structure member values which i
    wrapped. I execute this python code using call to RunScript (above
    function), it works fine for the first time, but from second time
    onwards I get an error - Type Error : in method
    <structurename_member>_set.
    Hence my question is the same python code worked for first call, but
    from 2nd call it is not working. Could any body help me where I am
    making mistake.

    Is extension modules does not work properly with multiple
    interpreters? Does any body had this behaviour when worked with
    extension modules and multiple interpreters creation for each thread.

    Thanks in Advance for the help.

    Vishnu
    vishnu, Mar 31, 2007
    #1
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Maciej Sobczak

    Multiple interpreters in a single process

    Maciej Sobczak, Jan 5, 2004, in forum: Python
    Replies:
    1
    Views:
    386
  2. Paul Miller
    Replies:
    4
    Views:
    318
    Paul Miller
    Jan 23, 2004
  3. Marcin Kalicinski
    Replies:
    3
    Views:
    600
    Graham Dumpleton
    Jun 10, 2007
  4. Replies:
    9
    Views:
    719
    Rhamphoryncus
    Apr 13, 2008
  5. Shea Martin

    embedded: multiple interpreters

    Shea Martin, Jan 24, 2007, in forum: Ruby
    Replies:
    0
    Views:
    93
    Shea Martin
    Jan 24, 2007
Loading...

Share This Page