From 8ad6b853fa6bb7b18a4bb9c43a1dfb46522bf611 Mon Sep 17 00:00:00 2001 From: "arnaud.morvan@camptocamp.com" Date: Wed, 17 Apr 2024 18:06:02 +0200 Subject: [PATCH] Always close browser --- thinkhazard/views/pdf.py | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/thinkhazard/views/pdf.py b/thinkhazard/views/pdf.py index 9f74647b..22f1a040 100644 --- a/thinkhazard/views/pdf.py +++ b/thinkhazard/views/pdf.py @@ -124,11 +124,12 @@ async def render_page(url): logger.info("Got: {}".format(url)) return BytesIO(await page.pdf({"format": "A4", "printBackground": True})) - chunks = await asyncio.gather(*[ - render_page(url) for url in pages - ]) - - await browser.close() + try: + chunks = await asyncio.gather(*[ + render_page(url) for url in pages + ]) + finally: + await browser.close() # merge all pages writer = PdfFileWriter()