Tommy Zong wrote:

> class easyExcel:

[... snip ...]

> However, I found a problem today - it works fine in single thread version
> but can not work properly in multi-thread version - If I move excel file
> operations to sub-thread, it will complain 'CoInitialize has not been
> called'. I noticed the exception is thrown in
> "Lib\site-packages\win32com\client\dynamic.py", I tried to add
> "pythoncom.CoInitialize()" in line 78 and "pythoncom.CoUninitialize()" in
> line 330, it will be ok. 

> 1.       After doing such modifications, the excel file will be opened as
> "read only" mode, how to avoid this?

No idea. Sounds improbable but I haven't tried it.

> 2.       Is it necessary to add these two lines? Is there any mistake I
> made?

Yes. If you want to use any kind of COM/DCOM routines
in a multithreaded environment, you must tell the
COM subsystem that you want threading, and possibly
what kind of threading you want. If you stick
"CoInitialize" into your favourite search engine
you'll get far more information than you really need.

Here's the authoritative page:

   http://msdn2.microsoft.com/en-us/library/ms678543.aspx

TJG
-- 
http://mail.python.org/mailman/listinfo/python-list

Reply via email to