home *** CD-ROM | disk | FTP | other *** search
/ Chip 2011 November / CHIP_2011_11.iso / Programy / Narzedzia / Calibre / calibre-0.8.18.msi / file_262 / atexit.pyo (.txt) < prev    next >
Encoding:
Python Compiled Bytecode  |  2011-09-09  |  1.4 KB  |  55 lines

  1. # Source Generated with Decompyle++
  2. # File: in.pyo (Python 2.7)
  3.  
  4. __all__ = [
  5.     'register']
  6. import sys
  7. _exithandlers = []
  8.  
  9. def _run_exitfuncs():
  10.     exc_info = None
  11.     while _exithandlers:
  12.         (func, targs, kargs) = _exithandlers.pop()
  13.         
  14.         try:
  15.             func(*targs, **kargs)
  16.         continue
  17.         except SystemExit:
  18.             exc_info = sys.exc_info()
  19.             continue
  20.             import traceback
  21.             print >>sys.stderr, 'Error in atexit._run_exitfuncs:'
  22.             traceback.print_exc()
  23.             exc_info = sys.exc_info()
  24.             continue
  25.         
  26.  
  27.     if exc_info is not None:
  28.         raise exc_info[0], exc_info[1], exc_info[2]
  29.  
  30.  
  31. def register(func, *targs, **kargs):
  32.     _exithandlers.append((func, targs, kargs))
  33.     return func
  34.  
  35. if hasattr(sys, 'exitfunc'):
  36.     register(sys.exitfunc)
  37. sys.exitfunc = _run_exitfuncs
  38. if __name__ == '__main__':
  39.     
  40.     def x1():
  41.         print 'running x1'
  42.  
  43.     
  44.     def x2(n):
  45.         print 'running x2(%r)' % (n,)
  46.  
  47.     
  48.     def x3(n, kwd = None):
  49.         print 'running x3(%r, kwd=%r)' % (n, kwd)
  50.  
  51.     register(x1)
  52.     register(x2, 12)
  53.     register(x3, 5, 'bar')
  54.     register(x3, 'no kwd args')
  55.