From: Michael Tremer Date: Sun, 9 Feb 2025 13:26:23 +0000 (+0000) Subject: registry: Stream blobs from a separate thread X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=010002ba7086ea7bc135fe86ca08c4a1e1ed0615;p=pbs.git registry: Stream blobs from a separate thread We need this to not block the main thread on really large blobs. Signed-off-by: Michael Tremer --- diff --git a/src/web/registry.py b/src/web/registry.py index 62359261..0bda117e 100644 --- a/src/web/registry.py +++ b/src/web/registry.py @@ -26,6 +26,7 @@ import json import tornado.web from . import base +from ..decorators import run_in_thread class BaseHandler(base.BaseHandler): """ @@ -50,6 +51,18 @@ class BaseHandler(base.BaseHandler): if blob: return blob + @run_in_thread + def stream_blob(self, blob): + """ + Streams the blob from a separate thread + """ + while True: + chunk = blob.read(1024 * 1024) + if not chunk: + break + + self.write(chunk) + async def write_error(self, *args, **kwargs): pass # Don't send any body @@ -152,13 +165,5 @@ class BlobOrManifestHandler(BaseHandler): # determine the length of the file without reading the whole thing first. # Done if we should not send the body - if not send_body: - return - - # Send the file - while True: - chunk = blob.read(1024 * 1024) - if not chunk: - break - - self.write(chunk) + if send_body: + await self.stream_blob(blob)