problem with embedding python 2.3 and importing win32 extensions

A

Axel Diener

I embed python interpreters in a C++ program.
For each script to execute I create a new interpreter.
In this environment I can use the win32 extensions only one time.
Here is a little piece of code to illustrate the problem:

int
main(int argc, char **argv)
{
Py_Initialize();
Py_SetProgramName(argv[0]);

PyThreadState *save_tstate=PyThreadState_Swap(NULL);
PyThreadState *state=Py_NewInterpreter();

int rc=PyRun_SimpleString("import pywintypes;import pythoncom");
//this works well
printf("%d\n",rc);

Py_EndInterpreter(state);

PyThreadState_Swap(save_tstate);

state=Py_NewInterpreter();

rc=PyRun_SimpleString("import pywintypes;import pythoncom");
//this and all further atemps will fail
printf("%d\n",rc);

Py_EndInterpreter(state);
PyThreadState_Swap(save_tstate);

Py_Finalize();
}

Here is the output auf this little program:

0
Traceback (most recent call last):
File "<string>", line 1, in ?
File "C:\uti\Python23\Lib\site-packages\pythoncom.py", line 3, in ?
pywintypes.__import_pywin32_system_module__("pythoncom", globals())
File "C:\uti\Python23\Lib\site-packages\win32\lib\pywintypes.py", line
9, in _
_import_pywin32_system_module__
import imp, sys, os
TypeError: 'NoneType' object is not callable
-1

I use

Python 2.3.3 (#51, Dec 18 2003, 20:22:39) [MSC v.1200 32 bit (Intel)] on win32

with

pywin32-200.win32-py2.3.exe
(same result for win32all-163)

The problem doesn't occur with Python 2.2 and win32all-157 due to different
import wrappers.

Is there any way to overcome this problem?

Thanks
Axel Diener
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,982
Messages
2,570,186
Members
46,744
Latest member
CortneyMcK

Latest Threads

Top