Hi,

first of all, just import pythoncom directly
<code>
import pythoncom
</code>

As far as where to put pythoncom.CoInitialize() I'm not certain but i think at 
the top (or start) of your whole application.. if it's threaded then call it 
for each thread (at the start)
"Initializes the COM library on the current thread and identifies the
concurrency model as single-thread apartment (STA). Applications must
initialize the COM library before they can call COM library functions ..."
from: http://msdn2.microsoft.com/en-us/library/ms678543(VS.85).aspx

Hope that helps,
Alex

> From: [EMAIL PROTECTED]
> To: python-win32@python.org
> Date: Thu, 24 Apr 2008 16:15:17 +0100
> Subject: [python-win32] Apache & mod_python & win32com
> 
> 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 = self.__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 = 
> dynamic._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 = pythoncom.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
> 
> _______________________________________________
> python-win32 mailing list
> python-win32@python.org
> http://mail.python.org/mailman/listinfo/python-win32

_________________________________________________________________
Play the Andrex Hello Softie Game & win great prizes 
http://www.thehellosoftiegame.co.uk
_______________________________________________
python-win32 mailing list
python-win32@python.org
http://mail.python.org/mailman/listinfo/python-win32

Reply via email to