Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

>But Flask does not give control of what happens when the client suddenly closes the connection.

It is so annoying that they don't give you a way to do this. I built an LLM inference API but am still working on how to cancel an inference job if a client cancels. I really don't want to rewrite my entire server in Twisted so I'll probably end up just building the HTTP responses like you did.



I believe the WSGI spec is a bit unclear on this but some WSGI servers can give back control to the app when the connection gets closed. I use Flask and Waitress for long-lived server side events and my app is notified when the client closes the connection before the end of the stream of events.


Flask is FOSS, maybe it is not too difficult to add support for this yourselves.


Can you not use teardown_request to run some clean up code after each request?




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: