CollinMa's picture
Publish NExT-GPT course code and actual execution records
37a409d verified
Raw History Blame Contribute Delete
1.15 kB
"""Check process identity as well as the saved pipeline state."""
import json
from datetime import datetime
from pathlib import Path
ROOT=Path(__file__).resolve().parents[1]
if __name__=='__main__':
import psutil
path=ROOT/'logs/pipeline-status.json'
state=json.loads(path.read_text(encoding='utf-8')) if path.exists() else {'status':'not_started'}
alive=False
if state.get('pid'):
try:
process=psutil.Process(state['pid'])
started=datetime.fromisoformat(state['started_at']).timestamp()
alive=abs(process.create_time()-started)<10 and 'local_pipeline.py' in ' '.join(process.cmdline())
except psutil.NoSuchProcess:
pass
except psutil.AccessDenied:
alive=None
state['coordinator_alive']=alive
if state.get('status')=='running' and alive is None:
state['effective_status']='process_visibility_limited'
elif state.get('status')=='running' and not alive:
state['effective_status']='interrupted'
else:
state['effective_status']=state.get('status')
print(json.dumps(state,ensure_ascii=False,indent=2))