You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
#!/usr/bin/env python
# -*- coding: utf8 -*-
import datetime
import os
import sys
def _now(format="%Y-%m-%d %H:%M:%S"):
return datetime.datetime.now().strftime(format)
##### It's usually called when the script starts to run, prints the timestamp and PID.
def job_start():
print("[%s][PID:%s] job_start" % (_now(), os.getpid()))
sys.stdout.flush()
##### Use this func. to combine the execution results of multiple hosts and display by group.
def job_success(msg):
print("[%s][PID:%s] job_success:[%s]" % (_now(), os.getpid(), msg))
sys.stdout.flush()
sys.exit(0)
##### Use this func. to combine the execution results of multiple hosts and display by group.
def job_fail(msg):
print("[%s][PID:%s] job_fail:[%s]" % (_now(), os.getpid(), msg))
sys.stdout.flush()
sys.exit(1)
if __name__ == '__main__':
job_start()
###### The script execution result is depends on the value of return/exit code, weather it success or failed.
###### If return code is 0, means success, otherwise failed.
###### In order to avoid abnormal standard output due to the buffer not being refreshed for a long time in Python scripts,
###### we recommended to use sys.stdout.flush() in the line following the print statement to forcibly flush the cached output to the console.
###### Start to writing your script code below this line.
原python脚本默认模板:
更改后:(中文)
更改后:(英文)
变化:
job_start
job_success
和job_fail
三个内置函数中的print后面增加了sys.stdout.flush()
方法,避免因io缓存导致输出堵塞The text was updated successfully, but these errors were encountered: