home *** CD-ROM | disk | FTP | other *** search
/ One Click 11 / OneClick11.iso / Bancos de Dados / Conversao / Mysql2Excel / Setup.exe / Mysql2Excel.exe / atexit.pyc (.txt) < prev    next >
Encoding:
Python Compiled Bytecode  |  2003-06-23  |  2.0 KB  |  63 lines

  1. # Source Generated with Decompyle++
  2. # File: in.pyc (Python 2.2)
  3.  
  4. '''
  5. atexit.py - allow programmer to define multiple exit functions to be executed
  6. upon normal program termination.
  7.  
  8. One public function, register, is defined.
  9. '''
  10. __all__ = [
  11.     'register']
  12. _exithandlers = []
  13.  
  14. def _run_exitfuncs():
  15.     '''run any registered exit functions
  16.  
  17.     _exithandlers is traversed in reverse order so functions are executed
  18.     last in, first out.
  19.     '''
  20.     while _exithandlers:
  21.         (func, targs, kargs) = _exithandlers.pop()
  22.         apply(func, targs, kargs)
  23.  
  24.  
  25. def register(func, *targs, **kargs):
  26.     '''register a function to be executed upon normal program termination
  27.  
  28.     func - function to be called at exit
  29.     targs - optional arguments to pass to func
  30.     kargs - optional keyword arguments to pass to func
  31.     '''
  32.     _exithandlers.append((func, targs, kargs))
  33.  
  34. import sys
  35.  
  36. try:
  37.     x = sys.exitfunc
  38. except AttributeError:
  39.     sys.exitfunc = _run_exitfuncs
  40.  
  41. if x != _run_exitfuncs:
  42.     register(x)
  43.  
  44. del sys
  45. if __name__ == '__main__':
  46.     
  47.     def x1():
  48.         print 'running x1'
  49.  
  50.     
  51.     def x2(n):
  52.         print 'running x2(%s)' % `n`
  53.  
  54.     
  55.     def x3(n, kwd = None):
  56.         print 'running x3(%s, kwd=%s)' % (`n`, `kwd`)
  57.  
  58.     register(x1)
  59.     register(x2, 12)
  60.     register(x3, 5, 'bar')
  61.     register(x3, 'no kwd args')
  62.  
  63.