Skip to content

Commit

Permalink
Fix hanging: stream every line instead of every page
Browse files Browse the repository at this point in the history
The conversion was hanging arbitrarily [1] on some systems. Sometimes it
would send the full page other times stop half-way. The most likely
explanation is that some container runtime buffer must have been filling
up and thus causing the hanging.

This is fixed by having multiple sys.stdout write commands (one per each
image line).

[1]: #627 (comment)
  • Loading branch information
deeplow committed Jan 18, 2024
1 parent 609b77e commit fb3e4f4
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion dangerzone/conversion/doc_to_pixels.py
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,13 @@ async def convert(self) -> None:
rgb_buf = pix.samples_mv
await self.write_page_width(pix.width)
await self.write_page_height(pix.height)
await self.write_page_data(rgb_buf)

# XXX send line by line or else on some systems the data stream may hang
# https://github.com/freedomofpress/dangerzone/pull/627#issuecomment-1892491968
for i in range(pix.height):
await self.write_page_data(
rgb_buf[i * pix.width * 3 : (i + 1) * pix.width * 3]
)

self.update_progress("Converted document to pixels")

Expand Down

0 comments on commit fb3e4f4

Please sign in to comment.