weird COM hazard

mic aldo123 at onet.pl
Fri Jan 23 08:43:49 EST 2004


I'm getting strange hazard while running MSIE automation script. This
concerns MSIE events, especially OnDownloadBegin and OnClosing but I bet
they're not the only ones. The simplified code looks like this:

from win32com.client import DispatchWithEvents

class ConnectionStatus: #this is 'static' class containing most of the
parameters needed from other parts of the script
    MainBusy = False
    ChildBusy = False

class MSIE:
    Main = DispatchWithEvents('InternetExplorer.Application',MainEvents)
    Child = DispatchWithEvents('InternetExplorer.Application',ChildEvents)
"""
    then I do some browsing on 'Main' here, especially to the page that
fires using JavaScript new window,
    that's being captured by Child object. Then the Child window is closed
by using JS window.close()
"""

class MainEvents:
    def OnDownloadBegin(self):
            ConnectionStatus.MainBusy = True

    def OnDocumentComplete(self):
            ConnectionStatus.MainBusy = True
"""
this way I catch most of the available events. The only operation I do is
set the ConnectionStatus class attributes
The same goes to ChildEvents:
"""
class ChildEvents:
    def OnDownloadBegin(self):
            ConnectionStatus.ChildBusy = True

    def OnDocumentComplete(self):
            ConnectionStatus.ChildBusy = True

The problem is that from time to time some of the child events raises
exception:

AttributeError: 'NoneType' object has no attribute 'ChildBusy'

and after a short debugging it looks like at some moment I loose the
reference to the ConnectionStatus class, though obviously I make no such
operation at all. As it happens 50% of times I run the same script and seems
to stop not only at the same event, I'm starting to believe that this is
kind of a bug in win32com. Does anybody experienced anything like that?

Thanks in advance,

Michal





More information about the Python-list mailing list