Skip to content

Commit

Permalink
handle better error in fifos
Browse files Browse the repository at this point in the history
  • Loading branch information
manatlan committed Jun 3, 2024
1 parent 361b93d commit 176e44a
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
7 changes: 3 additions & 4 deletions htagweb/fifo.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,10 +68,9 @@ async def com(self,command:str,**args) -> "str|dict": # for client only
frame = await fifo_in.readline()

#print("Client receive:",frame)
try:
c = json.loads(frame.strip())
except Exception:
raise Exception(f"com error : {frame}")
c = json.loads(frame.strip())
if "err" in c:
raise Exception(f"com error : {c['err']}")
return c["response"]


Expand Down
11 changes: 9 additions & 2 deletions htagweb/hrprocess.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,19 +136,26 @@ def destroy():

# log("recept command:",frame)
c=json.loads(frame.strip())
c["response"]=await cmd(**c)
try:
c["response"]=await cmd(**c)
except Exception as e:
c["err"]=str(e) #TODO: full error here ?

# Envoyer la réponse au client
await fifo_out.write(json.dumps(c) + '\n')
await fifo_out.flush()

if "err" in c:
raise Exception(c["err"])

if timeout_inactivity: # if timeout_inactivity is set
if time.monotonic() - time_activity > timeout_inactivity:
# it suicides after the timeout
log(f"TIMEOUT inactivity ({timeout_inactivity}s), suicide !")
break

except Exception as e:
log("error",e)
log("error (EXIT)",e)
finally:
f.removePipes()
log("EXITED (no more pipes)")
Expand Down

0 comments on commit 176e44a

Please sign in to comment.