[EMAIL PROTECTED] wrote:
Hello everyone

I'm developing a web application using mod_python and the apache web server. 
That application has to handle xml files and for that I'm using win32com with 
with MSXML.

My problem is, that apache spawns a new process / thread (not sure wether ist a process 
or thread. I think it's a thread) per http request. So when multiple users generated 
requests "at the same time" (new request before the first one is returned) I 
have multiple threads running. And that's where my win32com code is crashing...

Currently, for every request my code does the following (as an example):

return win32com.client.Dispatch("Msxml2.DOMDocument.6.0")

To get an empty MSXSML DOM object.

For multiple requests at the same time I get the following error:

 File "C:\Program Files\Apache Software 
Foundation\Apache2.2\TCRExceptionManagerData\database_library\database.py", line 24, 
in __init__
    self.__configFileSchema =elf.__XSDSchemaCache()

  File "C:\Program Files\Apache Software 
Foundation\Apache2.2\TCRExceptionManagerData\database_library\database.py", line 
1774, in __XSDSchemaCache
    return win32com.client.Dispatch("MSXML2.XMLSchemaCache.6.0")

  File "C:\Program 
Files\Python25\lib\site-packages\win32com\client\__init__.py", line 95, in Dispatch
    dispatch, userName 
=ynamic._GetGoodDispatchAndUserName(dispatch,userName,clsctx)

  File "C:\Program 
Files\Python25\lib\site-packages\win32com\client\dynamic.py", line 98, in 
_GetGoodDispatchAndUserName
    return (_GetGoodDispatch(IDispatch, clsctx), userName)

  File "C:\Program 
Files\Python25\lib\site-packages\win32com\client\dynamic.py", line 78, in 
_GetGoodDispatch
    IDispatch =ythoncom.CoCreateInstance(IDispatch, None, clsctx, 
pythoncom.IID_IDispatch)

com_error: (-2147221008, 'CoInitialize has not been called.', None, None)

I've read already a bit in this mailing list and someone mentioned that one 
need to call pythoncom.CoInitialize() and pythoncom.CoUninitialize(). But I 
don't know where exactly i should call those functions and wether that'll solve 
my problem... Also, when I do a 'import win32com.pythoncom' I get an error that 
the module 'pythoncom' does not exist!

I would be really happy if someone could help me and tell me how to make my 
win32com work for multiple threads!

Greetings
Dominique


I had this issue when I was using WMI in a thread. I basically just ended up calling CoInitialize() before I called my WMI object (or function) and then CoUninitialize() when the object/function returned.

However, if you're messing with XML, I would recommend one of the many excellent XML parsing libraries in Python. I've used the included DOM interface as well as lxml, which is more object-oriented. I've even used pyparsing in one of my scripts...it's pretty new, but the developer for it is very responsive and has good examples and even a small e-book on it.

Just some ideas...

Mike
_______________________________________________
python-win32 mailing list
python-win32@python.org
http://mail.python.org/mailman/listinfo/python-win32

Reply via email to