知行编程网知行编程网  2022-11-10 00:00 知行编程网 隐藏边栏  16 
文章评分 0 次,平均分 0.0
导语: 本文主要介绍了关于怎么停止python脚本的相关知识,包括终止python运行,以及南京栖霞区有序解除临时管控这些编程知识,希望对大家有参考作用。


如何停止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() 来实现的。

Python 2.4 新增了 subprocess 模块,官方推荐使用修改后的模块替换 os.system。因此,也可以这样写:

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

众多
,尽在python学习网,欢迎在线学习!

本文为原创文章,版权归所有,欢迎分享本文,转载请保留出处!

知行编程网
知行编程网 关注:1    粉丝:1
这个人很懒,什么都没写
扫一扫二维码分享