讓Python指令碼暫停執行的幾種方法__Python

來源:互聯網
上載者:User

轉自:讓Python指令碼暫停執行的幾種方法


 1.time.sleep(secs)

     參考文檔原文:

 

Suspend execution for the given number of seconds. The argument may be a floating point number to indicate a more precise sleep time. The actual suspension time may be less than that requested because any caught signal will terminate the sleep() following execution of that signal’s catching routine. Also, the suspension time may be longer than requested by an arbitrary amount because of the scheduling of other activity in the system.

 

     大意:

          讓程式執行暫停指定的秒數,參數可以是浮點型以指定精確的時間,但是程式真正暫停時間可能長於請求的時間也可能短於暫停時間。

2. raw_input( )

     通過等待輸入來讓程式暫停

3. os.system("pause")

     通過執行作業系統的命令來讓程式暫停,該函數是通過實現標準C函數system( )來實現的。

     Python2.4新加入了subprocess模組,而且官方建議使用改模組替換os.system所以,也可以這樣寫:

     subprocess.call("pause",shell=True)

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.