[python-win32] Python script jumps back to 'main' in long running win32 event

Robert Sudwarts robert.sudwarts at gmail.com
Thu Jun 24 16:43:26 CEST 2010


Hi,

I'm hoping that someone can help with this... I've seen some old posts which
I think may refer to this same issue but I'm having difficulty understanding
how to come up with a solution, and particularly where any
"PumpWaitingMessages" should be located and/or/how/whether
 pythoncom.CoInitializeEx(pythoncom.COINIT_MULTITHREADED) should be used.

The code processes data for 25/30 messages received back from the com object
but then seems to jump back to the 'if __name__ == '__main__' and passes
that same parameter (originally passed from the command line) and runs all
over again...

The process is intended to:
1. pass a parameter from the command line
2. open a [pickle] file to store the data
3. call a COM object with Dispatch events (to an EventHandler)
4. for each block of data received back into the EventHandler, drop it into
the pickle
5. close the pickle file

I'd be immensely grateful for any assistance you can give.
Rob


Essentially the skeleton code I have (and I hope it's intelligible) is as
follows:

if __name__ == '__main__':
     arg = sys.argv[1:]
     proc(arg[0])

def proc(arg):
    fh = file("thispickle.pkl", 'wb')
    x = Async(arg)     # see below
    fh.close()


[in a seperate module I have the following construct for the Dispatch]

class EventHandler:
    def onData(self, event):
         # do stuff with data in 'event'
         cPickle.dump(data, self.fh)
         # flag this as 'done'


class Async:
     def __init__(self, params):
             #pythoncom.CoInitializeEx(pythoncom.COINIT_MULTITHREADED)  #
should this go here??
             s = win32com.client.DispatchWithEvents('com_obj' ,
EventHandler)

             self.finished = False
             while not self.finished:
                   PumpWaitingMessages()
                   if messages_all_flagged:
                           self.finished = True
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-win32/attachments/20100624/67ae369b/attachment.html>


More information about the python-win32 mailing list