Embedding and threads ?

Bo Lorentsen bl at netgroup.dk
Wed May 29 06:13:06 EDT 2002


Hi ...

I have been looking for a way to embed Python into a C/C++ program, but
I have some problems understanding what to do, if I like to support
threads.

I like to de something like this :

<code>
/* Main or other thread */
Py_Object *pCode1, pCode2;
Py_Initealize();

pCode1 = Py_CompileString( "print \"fancy python code from DB\"", ... );
pCode2 = Py_CompileString( "print \"more fancy python code from DB\"",
.. );

...

/* Thread one */
PyObject *pLocals = makeLocals(); 

PyObject *pRes = PyEval_EvalCode( pCode1, pLocals, NULL );
...

/* Thread two */
PyObject *pLocals = makeLocals(); 

PyObject *pRes = PyEval_EvalCode( pCode2, pLocals, NULL );
...

</code>

Now is this possible ? 
Will each python code run separatly, in issolated environments ?
Will it coredump ?
Can I control what the python code is allowed to import, and where
stdout/err/in is directed ?
Are there any other way of controlling the execution environment of
earch thread, like getting a kind of execution context thingy ?
Do I ask too much ? :-)

I'm looking forward to some hints.

/BL






More information about the Python-list mailing list