<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                合規國際互聯網加速 OSASE為企業客戶提供高速穩定SD-WAN國際加速解決方案。 廣告
                ### 導航 - [索引](../genindex.xhtml "總目錄") - [模塊](../py-modindex.xhtml "Python 模塊索引") | - [下一頁](traceback.xhtml "traceback --- Print or retrieve a stack traceback") | - [上一頁](abc.xhtml "abc --- 抽象基類") | - ![](https://box.kancloud.cn/a721fc7ec672275e257bbbfde49a4d4e_16x16.png) - [Python](https://www.python.org/) ? - zh\_CN 3.7.3 [文檔](../index.xhtml) ? - [Python 標準庫](index.xhtml) ? - [Python運行時服務](python.xhtml) ? - $('.inline-search').show(0); | # [`atexit`](#module-atexit "atexit: Register and execute cleanup functions.") --- 退出處理器 - - - - - - [`atexit`](#module-atexit "atexit: Register and execute cleanup functions.") 模塊定義了清理函數的注冊和反注冊函數. 被注冊的函數會在解釋器正常終止時執行. [`atexit`](#module-atexit "atexit: Register and execute cleanup functions.") 會按照注冊順序的\*逆序\*執行; 如果你注冊了 `A`, `B` 和 `C`, 那么在解釋器終止時會依序執行 `C`, `B`, `A`. **注意:** 通過該模塊注冊的函數, 在程序被未被 Python 捕獲的信號殺死時并不會執行, 在檢測到 Python 內部致命錯誤以及調用了 [`os._exit()`](os.xhtml#os._exit "os._exit") 時也不會執行. 在 3.7 版更改: When used with C-API subinterpreters, registered functions are local to the interpreter they were registered in. `atexit.``register`(*func*, *\*args*, *\*\*kwargs*)將 *func* 注冊為終止時執行的函數. 任何傳給 *func* 的可選的參數都應當作為參數傳給 [`register()`](#atexit.register "atexit.register"). 可以多次注冊同樣的函數及參數. 在正常的程序終止時 (舉例來說, 當調用了 [`sys.exit()`](sys.xhtml#sys.exit "sys.exit") 或是主模塊的執行完成時), 所有注冊過的函數都會以后進先出的順序執行. 這樣做是假定更底層的模塊通常會比高層模塊更早引入, 因此需要更晚清理. If an exception is raised during execution of the exit handlers, a traceback is printed (unless [`SystemExit`](exceptions.xhtml#SystemExit "SystemExit") is raised) and the exception information is saved. After all exit handlers have had a chance to run the last exception to be raised is re-raised. 這個函數返回 *func* 對象,可以把它當作裝飾器使用。 `atexit.``unregister`(*func*)Remove *func* from the list of functions to be run at interpreter shutdown. After calling [`unregister()`](#atexit.unregister "atexit.unregister"), *func* is guaranteed not to be called when the interpreter shuts down, even if it was registered more than once. [`unregister()`](#atexit.unregister "atexit.unregister") silently does nothing if *func* was not previously registered. 參見 模塊 [`readline`](readline.xhtml#module-readline "readline: GNU readline support for Python. (Unix)")使用 [`atexit`](#module-atexit "atexit: Register and execute cleanup functions.") 讀寫 [`readline`](readline.xhtml#module-readline "readline: GNU readline support for Python. (Unix)") 歷史文件的有用的例子。 ## [`atexit`](#module-atexit "atexit: Register and execute cleanup functions.") 示例 The following simple example demonstrates how a module can initialize a counter from a file when it is imported and save the counter's updated value automatically when the program terminates without relying on the application making an explicit call into this module at termination. ``` try: with open("counterfile") as infile: _count = int(infile.read()) except FileNotFoundError: _count = 0 def incrcounter(n): global _count _count = _count + n def savecounter(): with open("counterfile", "w") as outfile: outfile.write("%d" % _count) import atexit atexit.register(savecounter) ``` Positional and keyword arguments may also be passed to [`register()`](#atexit.register "atexit.register") to be passed along to the registered function when it is called: ``` def goodbye(name, adjective): print('Goodbye, %s, it was %s to meet you.' % (name, adjective)) import atexit atexit.register(goodbye, 'Donny', 'nice') # or: atexit.register(goodbye, adjective='nice', name='Donny') ``` 作為 [decorator](../glossary.xhtml#term-decorator): 使用: ``` import atexit @atexit.register def goodbye(): print("You are now leaving the Python sector.") ``` 只有在函數不需要任何參數調用時才能工作. ### 導航 - [索引](../genindex.xhtml "總目錄") - [模塊](../py-modindex.xhtml "Python 模塊索引") | - [下一頁](traceback.xhtml "traceback --- Print or retrieve a stack traceback") | - [上一頁](abc.xhtml "abc --- 抽象基類") | - ![](https://box.kancloud.cn/a721fc7ec672275e257bbbfde49a4d4e_16x16.png) - [Python](https://www.python.org/) ? - zh\_CN 3.7.3 [文檔](../index.xhtml) ? - [Python 標準庫](index.xhtml) ? - [Python運行時服務](python.xhtml) ? - $('.inline-search').show(0); | ? [版權所有](../copyright.xhtml) 2001-2019, Python Software Foundation. Python 軟件基金會是一個非盈利組織。 [請捐助。](https://www.python.org/psf/donations/) 最后更新于 5月 21, 2019. [發現了問題](../bugs.xhtml)? 使用[Sphinx](http://sphinx.pocoo.org/)1.8.4 創建。
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看