Skip to content

Commit

Permalink
server: Update error handling
Browse files Browse the repository at this point in the history
  • Loading branch information
Jason Phan committed Apr 26, 2020
1 parent a6dedad commit fb7f609
Showing 1 changed file with 15 additions and 14 deletions.
29 changes: 15 additions & 14 deletions qubespdfconverter/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


###############################
Expand Down

0 comments on commit fb7f609

Please sign in to comment.