我有Python脚本的一部分。将使用shell脚本调用此脚本。你知道吗
try:
sqlContext.sql("create table {}.`{}` as select * from mytempTable".format(hivedb,table))
except Exception as e:
status = 'fail'
error_message = e
else:
status = 'success'
error_message = 'No error'
print ("{},{},{},{}".format(hivedb,table,status,error_message))
status == 'success'
sys.exit(1)
在上面的代码中,如果我使用status == 'success'
,那么在脚本运行的所有时间,甚至对于失败的作业,我都会得到success
。你知道吗
如果我同时使用sys.exit(1)
或两者,我总是会失败。你知道吗
当status
为'success'
时,如何使脚本执行成功,当status
为'fail'
时,如何使脚本执行失败?你知道吗
最简单的答案是删除try/except。如果您只是在异常情况下进行调用,您将得到对stderr的完全回溯,python将以非零退出状态退出。你知道吗
例如
相关问题 更多 >
编程相关推荐