import tornado.web
from . import base
+from ..decorators import run_in_thread
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
# 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)