Implemented the memory fix.
Changed app.py: • process_pft_pdf() now uses the uploaded file stream directly instead of copying the PDF into bytes. • Output now uses SpooledTemporaryFile, so larger generated PDFs spill to disk instead of staying fully in RAM. • Explicitly closes PdfReader objects after writing. • Removed @app.teardown_request gc.collect(), which was running too early and could break send_file. • Added response.call_on_close() cleanup so the generated PDF stream is closed only after Flask/Werkzeug finishes sending it. Changed Dockerfile: • Added Gunicorn --max-requests 50 --max-requests-jitter 10 as a production guardrail against PDF-library or allocator memory growth.
This commit is contained in:
+1
-1
@@ -15,4 +15,4 @@ COPY . .
|
||||
EXPOSE 5000
|
||||
|
||||
# Command to run the application using Gunicorn (production ready)
|
||||
CMD ["gunicorn", "--bind", "0.0.0.0:5000", "app:app"]
|
||||
CMD ["gunicorn", "--bind", "0.0.0.0:5000", "--max-requests", "50", "--max-requests-jitter", "10", "app:app"]
|
||||
|
||||
Reference in New Issue
Block a user