waiting for event from COM object

Miranda Evans mirandacascade at yahoo.com
Fri May 3 19:26:59 EDT 2002


Attempting to write Python script that:
 - is not a GUI application
 - communicates with a COM object 

The COM object provides:
 - a send method
 - a MessageReceived event

The COM object does not provide any sort of mechanism
(properties, methods or events) for handling a timeout.

The script's responsibility is to send a message to the
COM object and then wait until either:
 - COM object fires its MessageReceived event

     or

 - one minute has elapsed since message sent
whichever comes first.  If the MessageReceived event
fired before the one minute elapsed, the script returns
"message received" as soon as the event fires.  If one 
minute passes without the MessageReceived event firing, 
the script returns "timeout".

My guess as to some of the code:

import win32com.client
class exampleEvents:
   OnMessageReceived(self):
      # ?? stop the one minute clock and
      # ?? signal "message recieved"

sampobj = win32com.client.DispatchWithEvents("mysample.application", exampleEvents)
sampobj.send("sample transmission")
# ?? insert code here that keeps the script running until
# ?? either one minutes elapses or OnMessageReceived
# ?? event fired

My question: after the sampobj.send() method is called, how can the
script be constructed to remain running for up to one minute or until
the OnMessageReceived event fired?

I looked at several samples of python code for timer events, but
did not see how they could be fit into this application...is a
timer event the way to go (reminder: this is not a GUI application)?



More information about the Python-list mailing list