[C++-sig] Can anybody tell me the other difference between these 2 little programs?

yakumoklesk at yahoo.es yakumoklesk at yahoo.es
Thu Sep 11 17:58:35 CEST 2003


//First version
int main( int argc, char** argv )
{
	Py_Initialize();

	handle<> main_module(borrowed( PyImport_AddModule("__main__") ));
    	handle<> main_namespace(borrowed( PyModule_GetDict(main_module.get()) 
));

	handle<> modModuleLoader( PyImport_ImportModule( "ModuleLoader" ) );
	handle<> funLoadModules( PyObject_GetAttrString( modModuleLoader.get(), 
"LoadModules" ) );
	handle<> dtTree( PyObject_GetAttrString( modModuleLoader.get(), "dtTree" ) );
	
	handle<> funcPrintTree( PyObject_GetAttrString( dtTree.get(), "PrintTree" ) );
	PyObject* argFuncArgs = Py_BuildValue( "(i)", 1 );
	handle<> resNoneResult( PyEval_CallObject( funcPrintTree.get(), argFuncArgs 
) );
	Py_DECREF( argFuncArgs );

	Py_Finalize();

	return 0;
}

// Second versiona
void test()
{
	Py_Initialize();

	handle<> main_module(borrowed( PyImport_AddModule("__main__") ));
    	handle<> main_namespace(borrowed( PyModule_GetDict(main_module.get()) 
));

	handle<> modModuleLoader( PyImport_ImportModule( "ModuleLoader" ) );
	handle<> funLoadModules( PyObject_GetAttrString( modModuleLoader.get(), 
"LoadModules" ) );
	handle<> dtTree( PyObject_GetAttrString( modModuleLoader.get(), "dtTree" ) );
	
	handle<> funcPrintTree( PyObject_GetAttrString( dtTree.get(), "PrintTree" ) );
	PyObject* argFuncArgs = Py_BuildValue( "(i)", 1 );
	handle<> resNoneResult( PyEval_CallObject( funcPrintTree.get(), argFuncArgs 
) );
	Py_DECREF( argFuncArgs );
}
int main( int argc, char** argv )
{
	test();

	Py_Finalize();

	return 0;
}

The first difference I have found is that the first version exits with an error

Fatal Python error: PyThreadState_Get: no current thread

while the second version works OK.

Thanks in advance.
David Lucena.

PD.- Using VC++ 6.0 in debug mode, with python 2.2.3 debug libraries and DLL and 
Boost.Python debug libraries and DLL




More information about the Cplusplus-sig mailing list