I have a Pyramid site that needs to support downloading data on the fly. The user will go to an incident page, press a button, and it will pack the data into a temporary zip file and serve it. I've done downloads before using FileResponse on a persistent file, or setting the response headers (content-type and content-disposition) and setting the body to generated CSV. But this time the zip file content may be inconveniently large to fit into memory (250 MB) or too large (2 GB), and I want the zip file and its temporary source directory to be deleted at the end of the request.
My first thought is to open the file for reading, set 'response.body_file' to it, and delete the file, depending on Unix's ability to delay deleting the file until all open filehandles are closed. Is that likely to work through Waitress + Traefik (webserver) + load balancer? Or is there another way? Otherwise I could put it in a persistent directory of recent download files, but that would be more complicated and I'd have to have a job that prunes the directory, so I'd rather not pursue that route. The application is still on Pyramid 1.3 and Python 3.10. It will be upgraded in the next several months, but not in time for this feature. -- Mike Orr <[email protected]> -- You received this message because you are subscribed to the Google Groups "pylons-discuss" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To view this discussion visit https://groups.google.com/d/msgid/pylons-discuss/CAH9f%3Dur6%2BWQm5-OYwYGePg1VNj48tMq%3DAA9GtUmKYC0ZUe9-cA%40mail.gmail.com.
