By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,846 Members | 1,862 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,846 IT Pros & Developers. It's quick & easy.

problem with embedding python 2.3 and importing win32 extensions

P: n/a
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__("pytho ncom", 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
Jul 18 '05 #1
Share this question for a faster answer!
Share on Google+

This discussion thread is closed

Replies have been disabled for this discussion.