File size: 1,146 Bytes
1c9b5b6 37a409d 1c9b5b6 37a409d 1c9b5b6 37a409d 1c9b5b6 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 | """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))
|