<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 模塊索引") | - [下一頁](queue.xhtml "queue --- 一個同步的隊列類") | - [上一頁](subprocess.xhtml "subprocess --- 子進程管理") | - ![](https://box.kancloud.cn/a721fc7ec672275e257bbbfde49a4d4e_16x16.png) - [Python](https://www.python.org/) ? - zh\_CN 3.7.3 [文檔](../index.xhtml) ? - [Python 標準庫](index.xhtml) ? - [并發執行](concurrency.xhtml) ? - $('.inline-search').show(0); | # [`sched`](#module-sched "sched: General purpose event scheduler.") --- 事件調度器 **源碼:** [Lib/sched.py](https://github.com/python/cpython/tree/3.7/Lib/sched.py) \[https://github.com/python/cpython/tree/3.7/Lib/sched.py\] - - - - - - [`sched`](#module-sched "sched: General purpose event scheduler.") 模塊定義了一個實現通用事件調度程序的類: *class* `sched.``scheduler`(*timefunc=time.monotonic*, *delayfunc=time.sleep*)[`scheduler`](#sched.scheduler "sched.scheduler") 類定義了一個調度事件的通用接口。 它需要兩個函數來實際處理“外部世界” —— *timefunc* 應該可以在沒有參數的情況下調用,并返回一個數字(“時間”,以任何單位表示)。 如果 time.monotonic 不可用,則 *timefunc* 默認為 time.time。 *delayfunc* 函數應該用一個參數可調用,與 *timefunc* 的輸出兼容,并且應該延遲那么多時間單位。 每個事件運行后,還會使用參數 `0` 調用 *delayfunc*,以允許其他線程有機會在多線程應用程序中運行。 在 3.3 版更改: *timefunc* 和 *delayfunc* 參數是可選的。 在 3.3 版更改: [`scheduler`](#sched.scheduler "sched.scheduler") 類可以安全的在多線程環境中使用。 示例: ``` >>> import sched, time >>> s = sched.scheduler(time.time, time.sleep) >>> def print_time(a='default'): ... print("From print_time", time.time(), a) ... >>> def print_some_times(): ... print(time.time()) ... s.enter(10, 1, print_time) ... s.enter(5, 2, print_time, argument=('positional',)) ... s.enter(5, 1, print_time, kwargs={'a': 'keyword'}) ... s.run() ... print(time.time()) ... >>> print_some_times() 930343690.257 From print_time 930343695.274 positional From print_time 930343695.275 keyword From print_time 930343700.273 default 930343700.276 ``` ## 調度器對象 [`scheduler`](#sched.scheduler "sched.scheduler") 實例擁有以下方法和屬性: `scheduler.``enterabs`(*time*, *priority*, *action*, *argument=()*, *kwargs={}*)安排一個新事件。 *time* 參數應該有一個數字類型兼容的返回值,與傳遞給構造函數的 *timefunc* 函數的返回值兼容。 計劃在相同 *time* 的事件將按其 *priority* 的順序執行。 數字越小表示優先級越高。 執行事件意為執行 `action(*argument, **kwargs)`。 *argument* 是包含有 *action* 的位置參數的序列。 *kwargs* 是包含 *action* 的關鍵字參數的字典。 返回值是一個事件,可用于以后取消事件( 參見 [`cancel()`](#sched.scheduler.cancel "sched.scheduler.cancel") )。 在 3.3 版更改: *argument* 參數是可選的。 3\.3 新版功能: 添加了 *kwargs* 形參。 `scheduler.``enter`(*delay*, *priority*, *action*, *argument=()*, *kwargs={}*)安排延后 *delay* 時間單位的事件。 除了相對時間,其他參數、效果和返回值與 [`enterabs()`](#sched.scheduler.enterabs "sched.scheduler.enterabs") 的相同。 在 3.3 版更改: *argument* 參數是可選的。 3\.3 新版功能: 添加了 *kwargs* 形參。 `scheduler.``cancel`(*event*)從隊列中刪除事件。 如果 *event* 不是當前隊列中的事件,則此方法將引發 [`ValueError`](exceptions.xhtml#ValueError "ValueError")。 `scheduler.``empty`()如果事件隊列為空,則返回真值。 `scheduler.``run`(*blocking=True*)運行所有預定事件。 此方法將等待(使用傳遞給構造函數的 `delayfunc()` 函數)進行下一個事件,然后執行它,依此類推,直到沒有更多的計劃事件。 如果 *blocking* 為false,則執行由于最快到期(如果有)的預定事件,然后在調度程序中返回下一個預定調用的截止時間(如果有)。 *action* 或 *delayfunc* 都可以引發異常。 在任何一種情況下,調度程序都將保持一致狀態并傳播異常。 如果 *action* 引發異常,則在將來調用 [`run()`](#sched.scheduler.run "sched.scheduler.run") 時不會嘗試該事件。 如果一系列事件的運行時間比下一個事件之前的可用時間長,那么調度程序將完全落后。 不會發生任何事件;調用代碼負責取消不再相關的事件。 3\.3 新版功能: 添加了 *blocking* 形參。 `scheduler.``queue`只讀屬性按照將要運行的順序返回即將發生的事件列表。 每個事件都顯示為 [named tuple](../glossary.xhtml#term-named-tuple) ,包含以下字段:time、priority、action、argument、kwargs。 ### 導航 - [索引](../genindex.xhtml "總目錄") - [模塊](../py-modindex.xhtml "Python 模塊索引") | - [下一頁](queue.xhtml "queue --- 一個同步的隊列類") | - [上一頁](subprocess.xhtml "subprocess --- 子進程管理") | - ![](https://box.kancloud.cn/a721fc7ec672275e257bbbfde49a4d4e_16x16.png) - [Python](https://www.python.org/) ? - zh\_CN 3.7.3 [文檔](../index.xhtml) ? - [Python 標準庫](index.xhtml) ? - [并發執行](concurrency.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>

                              哎呀哎呀视频在线观看