[python-win32] Apache & mod_python & win32com

Dominique.Holzwarth at ch.delarue.com Dominique.Holzwarth at ch.delarue.com
Mon Apr 28 08:16:46 CEST 2008


The problem with apache tho is, that it starts the thread itself and I don't know wether my script runs on a new thread or not. I did some testing with calling CoInitialize at the start of my scripts and CoUnitialize at the end of my script (as suggested by others before) and it seemed to work...

Do I understand you correct, that you suggest to use CoInitializeEx instead? My scripts should all use the aparment threading model tho, but I can try and change to CoInitializeEx =)

As for the COM objects I'm requesting, these are:

win32com.client.Dispatch("MSXML2.XMLSchemaCache.6.0")
win32com.client.Dispatch("Msxml2.FreeThreadedDOMDocument.6.0")
win32com.client.Dispatch("Msxml2.DOMDocument.6.0")
win32com.client.Dispatch("Msxml2.XSLTemplate.6.0")

So for the DOM document there seem to be either version, but for the schema and template objects I don't know wether these are free-threaded or not and wether that matters at all... :-/ I have to admit that the whole COM stuff is a bit mysterious for me...

Greetings Dominique

-----Original Message-----
From: Mark Hammond [mailto:mhammond at skippinet.com.au]
Sent: Sonntag, 27. April 2008 09:20
To: Holzwarth, Dominique (Berne Bauhaus); python-win32 at python.org
Subject: RE: [python-win32] Apache & mod_python & win32com

> Thank you Rober & Alex for the answers :-) But I must admit that I'm
> still bit uncertain about that whole issue.
> As I understood apache it is creating a thread for every request
> anyway, or not?

No - given the docs posted before, they are created once and shared.  When a request completes, its thread becomes available to process the next request.
Thus, its better perf wise to only call the CoInit functions once as the thread starts.


> (and yes, on windows the MPM winnt is used) so wouldn't it be enough
> to just call CoInitialized() at the start of my (mod_python)
> python-handler and CoUnitialize() and the end of my handler? the
> try... finally you have added only for the case my script would
> "crash", right? so that the CoUnitialize() is called in that case as
> well?

CoInit functions can fail if someone else has beaten you to calling CoInit, and requested a different threading model.  Ideally, you should call CoInitializeEx(COINIT_MULTITHREADED), and if you happen to be using a free-threaded COM object, your threads will not interfere with each other at all.  Apartment threading (the default) may not perform as well.  Requesting free-threading should not hurt if the object is not free-threaded, but you would want to make sure :)

> The idea about the single thread and queue I don't really get to be
> honest... what sort of object would be passed in the queue? And how
> would I create that queue and the thread? I guess you thinking of some
> standard python modules (as there's probably a python module for
> everything =))?

Google for something like "consumer and producer pattern"

Cheers,

Mark





More information about the python-win32 mailing list