Problem with capturing exception

GoWtHaM NaRiSiPaLli <[email protected]> Thu, 5 Mar 2009 14:54:20 +0530
Newsgroups gmane.comp.python.pythoncard
Message-ID <[email protected]>
Hi All,

I am looking at a way to gracefully closing the PythonCard application and
report back as log give some information or do the clean up before ending
the script.
To present a sample, heres some code written over minimal.py script.

====================================================
from PythonCard import model

class Minimal(model.Background):

    def on_initialize(self, e):
        self.test = 'test code'
        print 'Inside Init'


if __name__ == '__main__':
    app = model.Application(Minimal)
    print help(app)
    #app.RedirectStdio('output.txt')
    try:
        app.MainLoop()
        print 'Action after the loop'
    except (KeyboardInterrupt,  SystemExit):
        print 'Program execution has been stopped by keyboard interrupt'
====================================================

It never prints the statement in except whenever I end the program with ctrl
+ c.

On a normal loop, like this- It works and prints the statement..
==========================
import time

try:
  while 1:
    time.sleep(1)
except KeyboardInterrupt:
  print 'Program execution has been stopped by keyboard interrupt'
===========================

Is there an alternate way of doing this so that I can capture the keyboard
interrupt before the script closes.

Thanks,
Gowtham N

------------------------------------------------------------------------------
Open Source Business Conference (OSBC), March 24-25, 2009, San Francisco, CA
-OSBC tackles the biggest issue in open source: Open Sourcing the Enterprise
-Strategies to boost innovation and cut costs with open source participation
-Receive a $600 discount off the registration fee with the source code: SFAD
http://p.sf.net/sfu/XcvMzF8H

_______________________________________________
Pythoncard-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/pythoncard-users