[C++-sig] Re: Presenting a Python embedding tutorial
Nicodemus
nicodemus at globalite.com.br
Thu Dec 12 00:50:41 CET 2002
Dirk Gerrits wrote:
>> A variation on this (a minimal Embedding class we developed here before
>> boost::python v2)?
>>
>> ScriptEngine::ScriptEngine()
>> {
>> if(Py_IsInitialized())
>> {
>> m_weControlPython = false;
>> }
>> else
>> {
>> Py_Initialize();
>> m_weControlPython = true;
>> }
>> }
>>
>> ScriptEngine::~ScriptEngine()
>> {
>> if (m_weControlPython)
>> {
>> Py_Finalize();
>> }
>> }
>
>
> Yes very nice. But I still think the static counter is needed for the
> sub-interpreters. How about this:
>
> interpreter()
> {
> // Create the main interpreter
> if (interpreter_count == 0)
> {
> if (Py_IsInitialized())
> {
> we_control_python = false;
> }
> else
> {
> Py_Initialize();
> we_control_python = true;
> }
> ...
> }
> // Create a sub-interpreter
> else
> {
> ...
> }
> interpreter_count++;
> }
> ~interpreter()
> {
> // Release the main interpreter
> if (interpreter_count == 1)
> {
> if (we_control_python)
> Py_Finalize();
> ...
> }
> // Release a sub-interpreter
> else
> {
> ...
> }
> interpreter_count--;
> }
>
> ??
>
> Dirk Gerrits
>
>
>
Wouldn't be more productive if we first focus in the requirements of a
python interpreter, instead of focusing on the implementation itself? 8)
In my opinion, a python::interpreter class should be able to (from the
top of my head):
- Run python code (PyRun_* friends).
- Register extension modules.
- Run in multiple instances.
Nicodemus.
More information about the Cplusplus-sig
mailing list