[Zope] Re: Zope and COM (was: Zope with alternate python)

Toby Dickenson htrd90@zepler.org
Sat, 29 May 1999 12:25:21 GMT


On Thu, 27 May 1999 15:22:01 -0000, you wrote:

>Unfortunately I am using Zope with IIS, not ZopeHTTPServer. My real goal
>here though is to get COM working with Zope. I have existing python
>scripts, when run with my own (not Zope's) python installation, which
>execute properly. Set up as external methods these scripts don't work.

I recommend you try the same external methods under ZopeHTTPServer. If you find they work under ZopeHTTPServer but not with IIS then I may have an answer:

ZopeHTTPServer is (by default) single threaded, therefore the com libraries get initialised when the pythoncom module is loaded (CoInitialize is called) and everything is happy

However, the pcgi server (behind IIS) uses multiple threads. You might find that a com-using external method will work once, but only once. The second request comes in on a different thread - CoInitialise has not been called - and very little of com will work.

The easiest solution for now is to call CoInitailize explicitly at the start of every external method that uses com. This ensures each thread is initialised as an STA (single threaded apartment), and the redundant calls (should you use the same external method in ZopeHTTPServer) do not cause any serious harm. Note that because you are running in an STA you must not store com object references between requests; you must recreate fresh objects each time.

There was some discussion on the list recently about who should be calling CoInitialise, and what type of apartment should be created. For some future version you may need to remove all those CoInitialise calls, but everything else should 'just work'.

I hope this helps.


Toby Dickenson