AW: [wxPython-users] Application crashes after running a wxPython application via MS ActiveScript

Klaus Nökel Klaus.Noekel at ptv.de
Fri Feb 15 04:21:31 PST 2008


Robin,

> >  
> > Some hypotheses:
> > - some remnants of wxPython window management live on, confusing 
> > Windows.
> > - the ActiveScript session has not really terminated, so 
> Python is still 
> > running, so wxPython has not been reclaimed by the GC, so 
> it is actually 
> > still running its main-loop
> > - our application still holds on to COM references which cause the 
> > ActiveScript session to continue to exist.
> 
> I've never investigated ActiveScript but something like #2 
> would be my 
> guess, with a little bit of #1 thrown in for good measure.

By now, I have pretty much ruled out #3, by eliminating almost all COM objects allocated during script execution. I should also say that ActiveScript execution in our own app has been heavily used for years, and it works flawlessly - except for these rare cases. That is no proof, but it still makes a fundamental error in our ActiveScript calling sequence unlikely.

> 
> Can I assume that each script is creating an application object and 
> calling MainLoop?  

Yes, and as the following example demonstrates, IF the problem occurs at all, it occurs already for the simplest of wxPython scripts:

import wx

class MyFrame(wx.Frame):
    pass


# end of class MyDialog


app = wx.PySimpleApp(0)
fm = MyFrame(None, -1, "")
fm.Show()
app.MainLoop()

The interesting observation is that often enough we run a (fairly complex) wxPython script and our own app continues without problems. The crash definitely depends on what our app wants to do AFTER a wxPython script has been run. In the particular case at hand, we want to show a modal dialog, and according to the call stack the crash occurs during AfxPumpMessage somewhere below CDialog::DoModal. Not very exotic.

> Does AS create new threads for these 
> scripts to run 
> in or will they all be run in the same thread?  If there is a way to 
> force them to use the same thread then I would try that.  

We certainly do not create a separate thread ourselves, and the ActiveScript engine is created as a CLSCTX_INPROC_SERVER. What COM then does behind the curtains is harder to tell for me.

> If 
> there is a 
> way for you to cause AS to do more cleanup of the interpreter between 
> scripts then try that too.  

I have carefully checked several AS code examples - from MS and other sources - and I cannot find any kind of clean-up that we miss in our code. The AS API is not terribly voluminous, so there simply are not a lot of things you could forget to do.

> Finally, if there is some way to share a 
> single wx.App and MainLoop then that would be good too.
> 

Unfortunately, that is not an option, as scripts are run independently of each other and with any amount of non-scripted, interactive use of our app in between. There simply is not a single wxPython app that lives forever.

Regards,
Klaus Noekel 




More information about the wxpython-users mailing list