Tomi
Tomi
RRunPod
Created by Tomi on 6/27/2024 in #⚡|serverless
Error Handling Issue: Updating Response Status in Python’s Runpod
Hello everyone! I encountered an issue where I need to raise an error in my handler, but I’ve found that in the Python’s runpod library, errors are added to a job_output list. There’s a condition where it searches for the error field to update the response status to FAILED. However, since the error is within an output list, it doesn’t recognize that field, and the status remains COMPLETED. This is my handler and here is where I raise the error
except Exception as e:
yield {"error": str(e)}
except Exception as e:
yield {"error": str(e)}
and this is the Runpod code
async def _sim_runsync(self, job_request: DefaultRequest) -> JobOutput:
""" Development endpoint to simulate runsync behavior. """
assigned_job_id = f"test-{uuid.uuid4()}"
job = TestJob(id=assigned_job_id, input=job_request.input)

if is_generator(self.config["handler"]):
generator_output = run_job_generator(self.config["handler"], job.__dict__)
job_output = {"output": []}
async for stream_output in generator_output:
job_output['output'].append(stream_output["output"])
else:
job_output = await run_job(self.config["handler"], job.__dict__)

if job_output.get('error', None):
return jsonable_encoder({
"id": job.id,
"status": "FAILED",
"error": job_output['error']
})

if job_request.webhook:
thread = threading.Thread(
target=_send_webhook,
args=(job_request.webhook, job_output), daemon=True)
thread.start()

return jsonable_encoder({
"id": job.id,
"status": "COMPLETED",
"output": job_output['output']
})
async def _sim_runsync(self, job_request: DefaultRequest) -> JobOutput:
""" Development endpoint to simulate runsync behavior. """
assigned_job_id = f"test-{uuid.uuid4()}"
job = TestJob(id=assigned_job_id, input=job_request.input)

if is_generator(self.config["handler"]):
generator_output = run_job_generator(self.config["handler"], job.__dict__)
job_output = {"output": []}
async for stream_output in generator_output:
job_output['output'].append(stream_output["output"])
else:
job_output = await run_job(self.config["handler"], job.__dict__)

if job_output.get('error', None):
return jsonable_encoder({
"id": job.id,
"status": "FAILED",
"error": job_output['error']
})

if job_request.webhook:
thread = threading.Thread(
target=_send_webhook,
args=(job_request.webhook, job_output), daemon=True)
thread.start()

return jsonable_encoder({
"id": job.id,
"status": "COMPLETED",
"output": job_output['output']
})
Any insights would be greatly appreciated!
7 replies