Skip to content

Commit

Permalink
Make tornado histogram endpoint non-blocking
Browse files Browse the repository at this point in the history
  • Loading branch information
annehaley committed Jan 24, 2025
1 parent 4434ceb commit 06c09e7
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions large_image/tilesource/jupyter.py
Original file line number Diff line number Diff line change
Expand Up @@ -499,13 +499,17 @@ def get(self) -> None:
class TileSourceHistogramHandler(tornado.web.RequestHandler):
"""REST endpoint to get image metadata."""

def get(self) -> None:
async def get(self) -> None:
kwargs = {k: ast.literal_eval(self.get_argument(k)) for k in self.request.arguments}
histogram = manager.tile_source._unstyled.histogram( # type: ignore[attr-defined]
**kwargs,
).get('histogram', [{}])
self.write(json.dumps(histogram, cls=NumpyEncoder))
self.set_header('Content-Type', 'application/json')

def fetch():
histogram = manager.tile_source._unstyled.histogram( # type: ignore[attr-defined]
**kwargs,
).get('histogram', [{}])
self.write(json.dumps(histogram, cls=NumpyEncoder))
self.set_header('Content-Type', 'application/json')

await tornado.ioloop.IOLoop.current().run_in_executor(None, fetch)

class TileSourceTileHandler(tornado.web.RequestHandler):
"""REST endpoint to serve tiles from image in slippy maps standard."""
Expand Down

0 comments on commit 06c09e7

Please sign in to comment.