Need help with COMObject for Zope

Tres Seaver tseaver at starbase.neosoft.com
Wed Apr 26 23:08:15 EDT 2000


In article <T8MN4.5091$v85.31034 at news-server.bigpond.net.au>,
Mark Hammond <mhammond at skippinet.com.au> wrote:
><deepak_marda at my-deja.com> wrote in message
>news:8e7jeo$s8c$1 at nnrp1.deja.com...
>
>> I created a COMObject with id = word and Dispatch
>> = "Word.Application". WHen I try to connect this
>> COM object, it raises the following exception
>> Error Type: com_error
>> Error Value: (-2147221008, 'CoInitialize has not
>> been called.', None, None)
>
>Add the 2 lines:
>import pythoncom
>pythoncom.CoInitialize()
>
>before your code, and it will almost certainly work.
>
>The Zope guys should document this fairly well.  Note that Zope is almost
>certainly initializing COM on a different thread than your code is being
>called on (hence you see this message) - but there are some serious
>implications with COM and threading.  I dont believe you will hit them
>here, but someone will sometime :-)

We have a bug in the Collector on the COMObject project for this issue:

  http://classic.zope.org:8080/Collector/842/view

The bug page has three distinct workarounds:  one is essentially what
Mark posted (it has some ugly issues, but will work, slowly, for most code);
one requires hooking the thread creation to perform the CoInitialize() then;
the third makes use of a "pseudo-thread-local" table to track whether
CoInitialize() has been called for the current thread yet.  I favor the
third, myself, as it can be done without modifying Zope to support an
unsupported product.

Take-the-COMObject-product....PLEASE!'ly

Tres.
-- 
---------------------------------------------------------------
Tres Seaver        tseaver at digicool.com     http://www.zope.org
Digital Creations



More information about the Python-list mailing list