[python-win32] Apache & mod_python & win32com

Mark Hammond mhammond at skippinet.com.au
Sun Apr 27 09:20:20 CEST 2008


> 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