From fb7f609d490635ac1b9f67b65960b7aafe5916c5 Mon Sep 17 00:00:00 2001
From: Jason Phan
Date: Sat, 25 Apr 2020 23:56:13 -0500
Subject: [PATCH] server: Update error handling
---
qubespdfconverter/server.py | 29 +++++++++++++++--------------
1 file changed, 15 insertions(+), 14 deletions(-)
diff --git a/qubespdfconverter/server.py b/qubespdfconverter/server.py
index 22c2ba3..e356159 100755
--- a/qubespdfconverter/server.py
+++ b/qubespdfconverter/server.py
@@ -188,22 +188,23 @@ async def convert_rep(irep, frep):
async def render(loop, page, pdfpath, rep):
try:
- irep_task = asyncio.create_task(get_irep(pdfpath, rep.initial, page))
- await irep_task
+ try:
+ irep_task = asyncio.create_task(get_irep(pdfpath, rep.initial, page))
+ await irep_task
- dim_task = asyncio.create_task(get_img_dim(rep.initial))
- convert_task = asyncio.create_task(convert_rep(rep.initial, rep.final))
- dim, _ = await asyncio.gather(dim_task, convert_task)
- except subprocess.CalledProcessError:
- raise
- except asyncio.CancelledError:
- cancel_task(irep_task)
- cancel_task(dim_task)
- cancel_task(convert_task)
- finally:
- await loop.run_in_executor(None, unlink, rep.initial)
+ dim_task = asyncio.create_task(get_img_dim(rep.initial))
+ convert_task = asyncio.create_task(convert_rep(rep.initial, rep.final))
+ dim, _ = await asyncio.gather(dim_task, convert_task)
+ except subprocess.CalledProcessError:
+ raise
+ finally:
+ await loop.run_in_executor(None, unlink, rep.initial)
- return (dim, rep.final)
+ return (dim, rep.final)
+ except asyncio.CancelledError:
+ await asyncio.gather(cancel_task(irep_task), cancel_task(dim_task),
+ cancel_task(convert_task))
+ raise
###############################