class A(object): count = 0 def __init__(self): A.count = A.count + 1 self.count = A.count print 'Creating %d' % self.count def __del__(self): print 'Deleting %d' % self.count def job(i): print 'job() start' a = A() if i <= 1: raise AttributeError() print 'job() end' def runserver(): i = 0 while True: i += 1 print 'While start' try: job(i) except AttributeError, e: print 'Catched AttributeError' print 'While end' print 'runserver() end' runserver()