def watch(pid, name="no name", check_interval=1):
""" check the given process has finished or not
if it finishes, then send out email notification
:param pid: the pid of monitoring process
:param name: the name of process, this is optional, only used for notification
:param check_interval: how long the monitoring process should wait before next check
:return: None
"""
msg = 'task “ {} ({}) ” on _{}_ just began executing! ✌'.format(name, pid, socket.gethostname())
configEmailClient().send_email(message=msg, topic="Task Submitted")
while psutil.pid_exists(pid):
time.sleep(check_interval)
msg = 'task “ {} ({}) ” on _{}_ finished executing ✋'.format(name, pid, socket.gethostname())
configEmailClient().send_email(message=msg, topic="Task Finished")
评论列表
文章目录