[Baypiggies] What is destructor expected behavior?
glen at glenjarvis.com
Thu Feb 28 16:25:10 CET 2008
This is awesome! Thanks for letting me know about the atexit
module. I don't need a guarantee that the program will exit properly
if it is killed. I just need the program to "normally" do some clean-
up in a predictable manner.
This library works perfectly (although I need to do some
redesign work to make this fit cleanly in my model).
Regardless, I greatly appreciate the help. That's awesome. =) I
hope your meeting went well =)
glen at glenjarvis.com
"You must be the change you wish to see in the world." -M. Gandhi
On Feb 27, 2008, at 1:32 PM, Alex Martelli wrote:
> On Wed, Feb 27, 2008 at 12:08 PM, Glen Jarvis <glen at glenjarvis.com>
>> Summary: Can I assume, 100% of the time, that a destructor is
>> called before
>> a program ends?
> No (reference loops for example inhibit that).
>> If not, what is the design pattern to "time" issues in Python
>> at program begin time/end time? Futher granularity into the object
>> would be very helpful and preferred.
> See http://docs.python.org/lib/module-atexit.html for a way to to
> ALMOST this; however, for a sufficiently hard crash of a program, no
> such guarantee can be offered in-process (in Python's atexit case, the
> lack of guarantee also applies to program-killed-by-signal and
> os._exit calls, but even if you could bypass those sufficiently hard
> crashes would STILL invalidate the guarantee, e.g. kill -9 ENSURES no
> more code in the harshy-killed process will run). The architecture
> pattern that may help with that issue is to have a separate "watchdog
> process" that detects whether the target process is alive or dead
> (exactly how best to do that varies by operating system, since the
> detection depends on services the OS is providing to your processes):
> that might trigger some code to run no matter how harshly and abruptly
> the target process dies (however you will need to run the watchdog on
> separate hardware if you also want to catch cases in which the whole
> machine running the target process suddenly loses power, so its OS
> also dies with no chance of recovery -- etc, etc).
> So, in brief, it depends on the level of guarantee you need...
More information about the Baypiggies