Response cleanup
See original GitHub issueIt would be nice to have a simple API to direct post-response cleanup efforts outside of the task. Consider the following example:
async def cleanup(request: Request, response: HTTPResponse):
print("sleeping")
await sleep(1)
print("done")
@app.get("/")
async def handler(request: Request):
response = await request.respond()
await response.send("foobar")
await response.eof()
response.cleanup(cleanup)
In this example, we would immediately schedule a task using add_task
API to allow the response to return as early as possible. But, it should also be smart enough to work even without eof()
being called such that it would wait for the response to be sent and cleaned before proceeding to cleanup. Then you could even have handlers like this and guarantee that cleanup
is run on a completed response.
async def cleanup(request: Request, response: HTTPResponse):
print("sleeping")
await sleep(1)
print("done")
@app.get("/")
async def handler(request: Request):
resp = json({"foo": "bar"})
resp.cleanup(cleanup)
return resp
Issue Analytics
- State:
- Created a year ago
- Comments:7 (7 by maintainers)
Top Results From Across the Web
Response, Cleanup, and Reporting Procedures
Describes procedure for response, cleanup, and reporting for all types of spills.
Read more >Natural Disaster Response and Cleanup - Princeton EHS
Cleanup and recovery activities involve exposure to hazardous conditions including contaminated floodwater, downed electrical power lines, mold, tree-trimmingΒ ...
Read more >Spill Response and Clean-Up
Major Chemical Spill* Β· Beyond capabilities and resources to clean Β· Large amount (volume) Β· Highly hazardous substance Β· Emits harmful/toxic vapor, gas,...
Read more >EPA's Response Techniques | US EPA
Temporarily moving residents affected by hazardous substance contamination while cleanup activities take place; and/or; Installing fences to prevent directΒ ...
Read more >Tornado Cleanup and Response | NIOSH - CDC
During cleanup activities physical, chemical and biological hazards may be present. Challenges faced by emergency response and recovery workers includeΒ ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
You are correct. Scrap the shortcut and letβs fix this for real.
I have no take on that. Only that sending the response inside handler was supposed to be first class API, and after-handler handling only a fallback that calls it (even if in practice most handlers would return a response, not send it).