Reputation: 361
I created custom tile source provider with python running tornado web server. On the server I generate on the fly the specific tile and output it as a "image/png" header format. To prevent blocking I did all the server stuff in async mode. Now I see that I get some errors on the server: "Task was destroyed but it is pending!".
To figure out if there is a Python/tornado problem I did test by running a lot of tile requests from the Python code directly (by using the same url as mapbox source). All of the results returned HTTP response result 200 OK, so the python code runs as it should.
In the end I figure out that maybe the mapbox js tile source is not properly define or it has a timeout that is too quick and cancels request before it was successfully finished.
This is the javascript code for adding raster tile source:
mapbox_obj.on('load', function(){
mapbox_obj.addSource('rad-data', {
"type": "raster",
"tiles": ["/tile/{x}/{y}/{z}.png"],
"tileSize": 512
});
mapbox_obj.addLayer({
"id": "rad-data-layer",
"type": "raster",
"source": "rad-data",
"minzoom": 0,
"maxzoom": 20,
'layout': {
'visibility': 'visible'
}
});
});
The Python code generates the tile on the fly and returns it back as a byte string:
TILE_SIZE = 512
img = Image.new('RGBA', size=(TILE_SIZE, TILE_SIZE), color=(0, 0, 0, 0))
img_b = io.BytesIO()
img.save(img_b, "PNG")
tile = img_b.seek(0)
for line in tile:
self.write(line)
self.set_header("Content-type", "image/png")
Most of the tiles are usually rendered properly, but some of them sometimes are not and the error is as I mentioned: "Task was destroyed but it is pending!".
It looks like all the calls for tiles are called at the same time and maybe that could be the issue for the tornado RequestHandler that handles the async mysql query and the generation of the tile images.
Thank you for your help, Toni
Upvotes: 0
Views: 193