From fe05ff9f882da216b077fb9bd15d7a5e4ed92ceb Mon Sep 17 00:00:00 2001 From: eric Date: Mon, 25 Mar 2019 12:47:04 -0400 Subject: [PATCH] don't stall on super big pdf files --- core/loaders/harvest.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/core/loaders/harvest.py b/core/loaders/harvest.py index f4a72a59..ff68c90d 100644 --- a/core/loaders/harvest.py +++ b/core/loaders/harvest.py @@ -158,8 +158,14 @@ def make_harvested_ebook(content, ebook, format, filesize=0): format=format, source=ebook.url, ) - new_ebf.file.save(path_for_file(new_ebf, None), ContentFile(content)) - new_ebf.save() + try: + new_ebf.file.save(path_for_file(new_ebf, None), ContentFile(content)) + new_ebf.save() + except MemoryError: #huge pdf files cause problems here + logger.error("memory error saving ebook file for %s", ebook.url) + new_ebf.delete() + return None, False + new_ebook = Ebook.objects.create( edition=ebook.edition, format=format,