[triangle-zpug] Using COM in threads

Lee Nelson lee_nelson at ncsu.edu
Mon Feb 18 19:07:04 CET 2008


I am still trying to learn Python and I am currently trying to troubleshoot
the following error:

 

Unhandled exception in thread started by <function get_data_thread at
0x00C27EB0

> 

Traceback (most recent call last):

  File "CFL_Daq.py", line 224, in get_data_thread

    data_response = scan2.GetReducedDataString(data_string)

  File "C:\Python25\lib\site-packages\win32com\client\dynamic.py", line 496,
in

__getattr__

    raise AttributeError, "%s.%s" % (self._username_, attr)

AttributeError: StrainSmart.SSDataConnection2.GetReducedDataString

 

I think this is related to my use of a COM object inside of a thread.
According to this example
(http://devnulled.com/content/2004/01/com-objects-and-threading-in-python/),
I tried importing the pythoncom module and adding the following lines to the
definition of my thread function:

 

sys.coinit_flags = 0

pythoncom.CoInitialize()

.

.

.

Pythoncom.CoUninitialize()

 

But I'm still getting the same error.  I have no trouble using this COM
object outside of threads.  Does anybody have any suggestions as to what I'm
doing wrong?  I don't really understand the reason for the sys.coinit_flags
or the CoInitialize() function so any resources that better explain the use
of COM objects in threads could also be useful.

 

Thanks,

 

Lee

 

Entire project can be downloaded here:
http://www.ce.ncsu.edu/centers/cfl/temp/CFL_Daq.py 

 

 

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/trizpug/attachments/20080218/93955be4/attachment.htm>


More information about the TriZPUG mailing list