Re: python com server clean up problem
by Raul Cota other posts by this author
Nov 28 2005 3:42PM messages near this date
view in the new Beta List Site
Re: python com server clean up problem
|
Creating and terminating a process using win32process
Trent Mick wrote:
> [Raul Cota wrote]
>
> >I hope somebody here can help me out here.
> >
> >I have a Python COM server which I call from Excel. The Python object is a
> >bit complex and its __del__ method is not called when the reference count
> >to the object from within Excel go to 0. For this reason I have a CleanUp
> >method that makes sure all the resources are released. My problem is that I
> >want to make sure that this CleanUp method is always called when there are
> >not more references to the COM server.
> >
> >So, my question is: is there a way to know when the reference count of the
> >COM object goes to 0 ? For example, when Excel does not use it anymore and
> >the variable is set to Nothing?
> >
> >
> >I looked quite a bit in the archive of the mailing list with no luck.
>
>
> I am far from an expert on this so, YMMV. You may have a reference cycle
> that is keeping Python's garbage collection from cleaning up your server
> object. You can try gc.collect() -- I think that is what it is called --
> to trigger immediate garbage collection to play with this. Perhaps the
> Python COM Server framework code is holding on to a reference of your
> object and you need to call some API to unregister it or shut it down,
> or something?
>
> You also might want to ask on python-list@[...].org to see if there are
> any PyWin32 users there that may have run into a similar issue.
>
> Cheers,
> Trent
>
yes, I definitely have a reference cycle which I break by making a call like this:
myPyComObj.CleanUp()
this allows for the resources to get cleaned up properly.
My problem is that I don't always know when to call this method.
For example, In Excel I define something like this in a module,
global myPyComObj as Object
Then in excel, I may have a button that instatiates my com server and puts it into myPyComOb
j. At
this point I can go into my Excel toolbox and click on "Design Mode" in order to add more bu
ttons or
controls or whatever. This action disables my code and will automatically force myPyComObj t
o
Nothing and I was never notified that this hapenned, therefore I couldn't call
myPyComObj.CleanUp()
Raul
_______________________________________________
ActivePython mailing list
ActivePython@[...].com
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
Other options: http://listserv.ActiveState.com/mailman/listinfo/ActivePython
Thread:
Raul Cota
Trent Mick
Raul Cota
|