weird COM hazard

M

mic

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
 
M

Mark Hammond

mic said:
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?

What environment is this being run in? The only way I could see this
being set to None externally is if Python itself is in the process of
shutting down. There is nothing in win32com that will prevent Python
terminating while COM objects are alive, so there is the potential that
an external program tries to call back into Python during shutdown. I
can't see how this could happen using Python.exe though.

It is certainly nothing that has been reported before.

Mark.
 
M

mic

I've found the walkaround by setting within the child event class

constructor the local attribute that's equal to the external status class. I

can then reach the status without previously mentioned, random exceptions.

Strange, but works ok. Now I'm just investigating why my COM proxy object

returns at first string 'Microsoft Internet Explorer' and after a while:

win32com.client.COMEventClass. Does anyone know why?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Staff online

Members online

Forum statistics

Threads
474,176
Messages
2,570,947
Members
47,498
Latest member
log5Sshell/alfa5

Latest Threads

Top