problem with embedding python 2.3 and importing win32 extensions

Axel Diener axel.diener at orsoft.de
Wed Feb 11 02:14:13 EST 2004


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



More information about the Python-list mailing list