[Zope-dev] Zope and Com : CoInitialize done on each thread by Zserver?

Brian Lloyd Brian@digicool.com
Mon, 30 Aug 1999 14:26:52 -0400


Hi Brad,

I've been out for the last week, so ignore me if this has been
answered already...

> I'm working on an ADO DA for Z2. I'll need to do two things 
> to get this to 
> work correctly with Zope 2.
> 
> 1. Before win32com is imported, set sys.coinit_flags=0
> 2. In each thread, call CoInitializeEx(COINIT_FREETHREADED)
> 
> I've seen mentioned earlier on this list that Z2 was already calling 
> CoInitialize, but I can't find it in any .py files.

The win32 binary Zope dist. includes a subset of the win32
extensions, but _not_ win32com - that would open up many
new cans of worms having to due with COM versions etc. that
we don't want to get into (and that Mark is already doing a
good job dealing with in his distribution). So, z2 does not
try to call CoInitialize currently (and won't anytime soon).

Your need to do these things early in the startup code is 
similar to some things others have needed, and we've been
thinking about adding a more general-purpose hook, where
Zope will probably be willing try to import a site-specific 
module very early in the startup process. Then site maintainers
will be able to do whatever they need to do (add things to
the path, init COM, etc.) without hacking the Zope sources.

Your COM problem exposes a new twist, though. If CoInitialize
needs to be called for each thread, then the general-purpose
early import hook wouldn't quite be enough for you. The site-
specific module hook won't make it into 2.0 final anyway, so
we'll try to think about this for a future version. It sounds
like what we may need is a sort of way to register functions
that should be called on thread creation (and probably also
destruction).


Brian Lloyd        brian@digicool.com
Software Engineer  540.371.6909              
Digital Creations  http://www.digicool.com