From 3a22bfd7afcc99a5f2ee3bedde0f17c53c21e2bf Mon Sep 17 00:00:00 2001 From: bwarsaw Date: Tue, 28 Mar 2000 17:19:30 +0000 Subject: atexit(): A function for sys.exitfunc which will attempt to guarantee that the MailList object is unlocked when the script exits. --- bin/withlist | 25 +++++++++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) (limited to 'bin') diff --git a/bin/withlist b/bin/withlist index 3ddd9ed7f..2382d61b5 100644 --- a/bin/withlist +++ b/bin/withlist @@ -104,6 +104,22 @@ def usage(msg='', code=1): sys.exit(code) +def atexit(): + """Unlock a locked list, but do not implicitly Save() it. + + This does not get run if the interpreter exits because of a signal, or if + os._exit() is called. It will get called if an exception occurs though. + """ + global m + if not m: + return + if m.Locked(): + print 'Unlocking (but not saving) list:', m.internal_name() + m.Unlock() + print 'Finalizing' + del m + + def main(): global m @@ -131,8 +147,10 @@ def main(): # first try to open mailing list print 'Loading list:', listname, - if lock: print '(locked)' - else: print '(unlocked)' + if lock: + print '(locked)' + else: + print '(unlocked)' m = MailList(listname, lock=lock) @@ -150,4 +168,7 @@ def main(): print 'Running %s.%s()' % (module, callable), '...' r = getattr(mod, callable)(m) + + +sys.exitfunc = atexit main() -- cgit v1.3