Difference between exit() and sys.exit() in Python
Difference between exit() and sys.exit() in Python - Stack Overflow https://stackoverflow.com/questions/6501121/difference-between-exit-and-sys-exit-in-python

def ctrl_runtime():
if time.time() - ctrl_start >= max_script_time:
s = '%s%s%s%s%s' % ('程序开始执行时间', ctrl_start, '执行时间阈值', max_script_time, '终止执行')
logging.info(s)
print(s)
sys.exit(s)

def ctrl_runtime(exit_type=''):
if time.time() - ctrl_start >= max_script_time:
s = '%s%s%s%s%s%s%s%s%s' % (
'程序开始执行时间', ctrl_start, '执行时间阈值', max_script_time, '终止执行', ' exit_type =', exit_type, ' threadID ',
threading.get_ident())
logging.info(s)
if exit_type == '':
exit(s)
elif exit_type == 'sys':
sys.exit(s)
elif exit_type == 'os':
# an integer is required
# Required argument 'status' (pos 1) not found
os._exit(-1024)
Sat, 02 Dec 2017 15:55:55 chk_url_status_ordertab_notexpire.py[line:84] INFO DB (2003, "Can't connect to MySQL server on 'rm-xyz.mysql.xyz.acom.com' (timed out)")[thread:139775600219904][process:8191]
Sat, 02 Dec 2017 15:56:31 chk_url_status_ordertab_notexpire.py[line:84] INFO DB (2003, "Can't connect to MySQL server on 'rm-xyz.mysql.xyz.acom.com' (timed out)")[thread:139775029778176][process:8191]
Sat, 02 Dec 2017 15:59:20 chk_url_status_ordertab_notexpire.py[line:185] ERROR 20171202 15:58:29 threadID 139775080134400www.abc.cn/info/35028470.html DB Exception- (2003, "Can't connect to MySQL server on 'rm-xyz.mysql.xyz.acom.com' (timed out)")[thread:139775080134400][process:8191]
Sat, 02 Dec 2017 16:04:36 chk_url_status_ordertab_notexpire.py[line:84] INFO DB (2003, "Can't connect to MySQL server on 'rm-xyz.mysql.xyz.acom.com' (timed out)")[thread:139774509692672][process:8191]
Sat, 02 Dec 2017 16:16:33 chk_url_status_ordertab_notexpire.py[line:84] INFO DB (2003, "Can't connect to MySQL server on 'rm-xyz.mysql.xyz.acom.com' (timed out)")[thread:139773964429056][process:8191]
Sat, 02 Dec 2017 18:16:53 chk_url_status_ordertab_notexpire.py[line:46] INFO 程序开始执行时间1512205940.803967执行时间阈值3600终止执行 exit_type =os threadID 140530566547200[thread:140530566547200][process:31060]
您在 /var/spool/mail/root 中有邮件
From root@hadoop1.localdomain Sat Dec 2 17:22:41 2017
Return-Path: <root@hadoop1.localdomain>
X-Original-To: root
Delivered-To: root@hadoop1.localdomain
Received: by hadoop1.localdomain (Postfix, from userid 0)
id 80D294FC113C; Sat, 2 Dec 2017 17:22:41 +0800 (CST)
From: "(Cron Daemon)" <root@hadoop1.localdomain>
To: root@hadoop1.localdomain
Subject: Cron <root@hadoop1> python /home/data/crontab_chk_url/personas/trunk/plugins/spider/chk_url_status.py &> /dev/null
Content-Type: text/plain; charset=UTF-8
Auto-Submitted: auto-generated
Precedence: bulk
X-Cron-Env: <XDG_SESSION_ID=725>
X-Cron-Env: <XDG_RUNTIME_DIR=/run/user/0>
X-Cron-Env: <LANG=zh_CN.UTF-8>
X-Cron-Env: <SHELL=/bin/sh>
X-Cron-Env: <HOME=/root>
X-Cron-Env: <PATH=/usr/bin:/bin>
X-Cron-Env: <LOGNAME=root>
X-Cron-Env: <USER=root>
Message-Id: <20171202092241.80D294FC113C@hadoop1.localdomain>
Date: Sat, 2 Dec 2017 17:22:41 +0800 (CST)
/bin/sh: 行 1: 7295 已终止 python /home/data/crontab_chk_url/personas/trunk/plugins/spider/chk_url_status.py &>/dev/null
Difference between exit() and sys.exit() in Python的更多相关文章
- Python程序退出方式(sys.exit() os._exit() os.kill() os.popen(...))
对于如何结束一个Python程序或者用Python操作去结束一个进程等,Python本身给出了好几种方法,而这些方式也存在着一些区别,对相关的几种方法看了并实践了下,同时也记录下. 参考: Pytho ...
- python在运行时终止执行 sys.exit
使用sys.exit 或者exit,quit均可以退出执行 # 程序执行中,需要时停止执行 import sys if __name__ == '__main__': for ii in range( ...
- Python os._exit() sys.exit()
os._exit()会直接将python程序终止,之后的所有代码都不会继续执行. sys.exit()会引发一个异常:SystemExit,如果这个异常没有被捕获,那么python解释器将会退出.如果 ...
- Python中 os._exit() sys.exit() exit()区别
Python退出程序的方式有两种:os._exit(), sys.exit() 1)os._exit() 直接退出 Python程序,其后的代码也不会继续执行. 2)sys.exit() 引发一个 S ...
- python之 sys.exit() os._exit() exit() quit()的简单使用
python之sys.exit() os._exit() exit() quit()的简单使用 1>sys.exit() >>> import sys>>> ...
- python基础之 Python os._exit() sys.exit() exit()区别
Python退出程序的方式有两种:os._exit(), sys.exit() 1)os._exit() 直接退出 Python程序,其后的代码也不会继续执行. 2)sys.exit() 引发一个 S ...
- python sys.exit()函数说明
sys.exit()函数是通过抛出异常的方式来终止进程的,也就是说如果它抛出来的异常被捕捉到了的话程序就不会退出了. #!/usr/bin/python #!coding:utf-8 import s ...
- python中sys.exit()和os._exit(0)退出程序
python中退出程序的两种方法,0为默认状态,可以为空,两者均会退出当前运行的程序,os._exit(0)中的0不能省略 sys.exit(0):可以捕获SystemExit异常,然后做相应的清理工 ...
- Python第十天 print >> f,和fd.write()的区别 stdout的buffer 标准输入 标准输出 从控制台重定向到文件 标准错误 重定向 输出流和输入流 捕获sys.exit()调用 optparse argparse
Python第十天 print >> f,和fd.write()的区别 stdout的buffer 标准输入 标准输出 从控制台重定向到文件 标准错误 重定向 输出流和 ...
随机推荐
- iOS大转盘抽奖
功能 点击大转盘旋转后固定到某个自己可以确定的位置 结构 转盘,开始按钮,指针 技术 CADisplayLink不停重绘,CGAffineTransform旋转,简单数学公式 核心代码 1.使用CAD ...
- PAT天梯赛练习题——L3-003. 社交集群(并查集按秩合并)
L3-003. 社交集群 时间限制 1000 ms 内存限制 65536 kB 代码长度限制 8000 B 判题程序 Standard 作者 陈越 在社交网络平台注册时,用户通常会输入自己的兴趣爱好, ...
- 干货 | Elasticsearch Nested类型深入详解
在Elasticsearch实战场景中,我们或多或少会遇到嵌套文档的组合形式,反映在ES中称为父子文档. 父子文档的实现,至少包含以下两种方式: 1)父子文档 父子文档在5.X版本中通过parent- ...
- BZOJ 3856: Monster【杂题】
Description Teacher Mai has a kingdom. A monster has invaded this kingdom, and Teacher Mai wants to ...
- POJ 1125 Stockbroker Grapevine【floyd】
很裸的floyd #include<cstdio> #include<string.h> #include<algorithm> #define maxn 201 ...
- spring工作机制及为什么要用?
spring工作机制及为什么要用?1.spring mvc请所有的请求都提交给DispatcherServlet,它会委托应用系统的其他模块负责对请求进行真正的处理工作.2.DispatcherSer ...
- kail Linux 安装Parallels Tools
网上好多都是Parallels8的 针对Parallels 9 的还真不好找..... 自己捣鼓了一阵 终于可以安装了,但还是有错误,因为公司网络太不给力....回家再测试吧 1.在桌面新建一个文件夹 ...
- css3 改变默认选中文本背景色和文本颜色
::selection { background:#d3d3d3; color:#555; } ::-moz-selection { background:#d3d3d3; color:#555; } ...
- Python使用eval强制转换字符串为字典时报错:File "<string>", line 1, in <module> NameError: name 'nan' is not defined
文本中保存的内容为: { 'QQQ': [0.067, 0.167, 0.2, 0.033, 0.233, 0.267, 0.1, 0.133], 'TTT': [0.5, 0.375, 0.25, ...
- springboot主要注解及其作用
1.注解(annotations)列表 @SpringBootApplication:包含了@ComponentScan.@Configuration和@EnableAutoConfiguration ...