sanic-org / sanic

Accelerate your web app development | Build fast. Run fast.

Home Page:https://sanic.dev

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

How to avoid abort when the code throw an Exception

Huelse opened this issue · comments

Link to code

No response

Proposal

code:

@app.post("/evaluate", name="evaluate")
async def handler(request):
    # load from ctypes cdll
    app.ctx.lib.evaluate()

logs:

[2024-02-21 02:43:17 +0000] - (sanic.access)[INFO][192.168.65.1:59074]: POST http://localhost:8000/edcc/create  500 579
terminate called after throwing an instance of 'cv::Exception'
  what():  OpenCV(4.8.1) /opt/opencv-4.8.1/modules/imgcodecs/src/loadsave.cpp:802: error: (-215:Assertion failed) !buf.empty() in function 'imdecode_'

This will abort the worker(thread), and I can't use try-except to handle it. I want to ignore it and keep the worker going on or catch the exception and return in json, not abort it.

Thanks a lot!

Additional context

No response

Is this a breaking change?

  • Yes

good-for-nothing