[python-win32] COM AttributeError Inquiry

Mark Hammond mhammond at skippinet.com.au
Wed Nov 19 22:53:50 CET 2008


Search this mailing list for discussions about the COM threading model.  In
short, you can't create a COM object on one thread and use it on another -
the object must be marshalled.

 

Cheers,

 

Mark

 

From: python-win32-bounces+skippy.hammond=gmail.com at python.org
[mailto:python-win32-bounces+skippy.hammond=gmail.com at python.org] On Behalf
Of Mike O'Driscoll
Sent: Thursday, 20 November 2008 4:40 AM
To: python-win32 at python.org
Subject: [python-win32] COM AttributeError Inquiry

 

Hi,

 

First time contacting this mailing list. please forgive and discrepancies I
may make.

 

I have a threaded module with an internal com object.  If I make a call from
outside the module everything works ok.

If I make a call internal to the module it decides to give me the following
exception:

 

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

__getattr__

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

AttributeError: MyApp.AutomationProxy.Control

 

#################Code Snippet##################

 

import win32com.client

from threading import Thread, Event

import thread, threading

 

class AppController(Thread):

    def __init__(self):

        """Set up the class"""

        Thread.__init__(self)

        self.stopevent = threading.Event()

        self.app = win32com.client.Dispatch("MyApp.AutomationProxy")

        if not(self.app):

            print "Could not open MyApp Application"

            exit(1)

 

    def join(self, timeout=None):

        """Stop the thread and wait for it to finish"""

        del self.app

        print "App Finished"

        self.stopevent.set()

        Thread.join(self, timeout)

 

    def run(self):

            while not self.stopevent.isSet():

self.app.Control("myCommand") #Exception raised Here!?

#--------------------------------------------------

# Main Program

#--------------------------------------------------

 

if __name__ == '__main__':

    appCtrl = AppController()

    appCtrl.start()

   

    appCtrl.app.Control("myCommand") #Exception NOT raised?

 

    print "Press Any Key to Quit"

    import msvcrt

    while not msvcrt.kbhit():

        pass

 

# Gobble the key.

msvcrt.getch()

rtgCtrl.join()

exit(0)

 

#################End Code########################

 

I'm confused as to why using the object can complete the call, but when
calling within the class raises the attributeError exception.

Does the threading have something to do with it? (I have other threads like
this but removed to keep this short)

Any help appreciated.

 

Thanks,

 

Mike O'Driscoll
Intern Software Application Developer
3G Architecture | RIM Cellular Technologies

 

--------------------------------------------------------------------- 
This transmission (including any attachments) may contain confidential
information, privileged material (including material protected by the
solicitor-client or other applicable privileges), or constitute non-public
information. Any use of this information by anyone other than the intended
recipient is prohibited. If you have received this transmission in error,
please immediately reply to the sender and delete this information from your
system. Use, dissemination, distribution, or reproduction of this
transmission by unintended recipients is not authorized and may be unlawful.


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-win32/attachments/20081120/d76a347e/attachment-0001.htm>


More information about the python-win32 mailing list