Project

General

Profile

« Previous | Next » 

Revision 985

exc.py: Generalize ExTracker to not just print the # of errors at exit. Instead, provide an exit() method that the ExTracker creator can call at exit to set the exit status to the # of errors. This fixes the Python bug where a benign error message was printed if SystemExit was raised in an atexit function.

View differences:

exc.py
35 35
class ExTracker:
36 36
    def __init__(self):
37 37
        self.e_ct = 0
38
        def at_exit():
39
            sys.stderr.write(self.msg()+'\n')
40
            if self.e_ct > 0: raise SystemExit(e_ct_exit_status(self.e_ct))
41
        atexit.register(at_exit)
42 38
    
43 39
    def msg(self): return 'Encountered '+str(self.e_ct)+' error(s)'
44 40
    
45 41
    def track(self, e, **format):
46 42
        self.e_ct += 1
47 43
        print_ex(e, **format)
44
    
45
    def exit(self):
46
        if self.e_ct > 0: raise SystemExit(e_ct_exit_status(self.e_ct))
48 47

  
49 48
class ExPercentTracker(ExTracker):
50 49
    def __init__(self, iter_text='iteration'):

Also available in: Unified diff