Skip to content

Commit

Permalink
fix hangs and ci
Browse files Browse the repository at this point in the history
  • Loading branch information
SimonDanisch committed Aug 9, 2024
1 parent b453463 commit 1e3bb98
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 26 deletions.
6 changes: 2 additions & 4 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,7 @@ jobs:
version: 1
arch: x64
- uses: julia-actions/cache@v2
- run: sudo apt-get update && sudo apt-get install -y xorg-dev mesa-utils xvfb libgl1 freeglut3-dev libxrandr-dev libxinerama-dev libxcursor-dev libxi-dev libxext-dev libcairo2-dev libfreetype6-dev libffi-dev libjpeg-dev libpng-dev libz-dev
- name: Install pkgs dependencies
run: xvfb-run -s '-screen 0 1024x768x24' julia --project=@. -e 'using Pkg; pkg"add https://github.com/JuliaGeo/TileProviders.jl https://github.com/JuliaGeo/MapTiles.jl"'
- run: sudo apt-get update && sudo apt-get install -y xorg-dev mesa-utils xvfb libgl1 freeglut3-dev libxrandr-dev libxinerama-dev libxcursor-dev libxi-dev libxext-dev xsettingsd x11-xserver-utils
- uses: julia-actions/julia-runtest@v1
with:
prefix: xvfb-run -s '-screen 0 1024x768x24'
prefix: DISPLAY=:0 xvfb-run -s '-screen 0 1024x768x24'
7 changes: 0 additions & 7 deletions docs/src/points_poly_text.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,6 @@ show map

````@example plottypes
m = Tyler.Map(extent; provider, size=(1000, 600))
# wait for tiles to fully load
wait(m)
save("map_plottypes.png", current_figure()) # hide
nothing # hide
````

![](map_plottypes.png)
Expand Down Expand Up @@ -72,7 +68,4 @@ text!(pts2, text = "Basic Example"; fontsize = 30,
color = :darkblue, align = (:center, :center)
)
m
save("map_plottypes_all.png", current_figure()) # hide
nothing # hide
````
![](map_plottypes_all.png)
10 changes: 2 additions & 8 deletions docs/src/whale_shark.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,7 @@ fig = Figure(; size = (1200, 600))
ax = Axis(fig[1,1])
m = Tyler.Map(Rect2f(Rect2f(lomn - δlon/2, lamn-δlat/2, 2δlon, 2δlat));
provider, figure=fig, axis=ax)
wait(m)
save("whale_init.png", fig) # hide
nothing # hide
````
![](whale_init.png)

## Initial point

Expand All @@ -79,9 +75,7 @@ objscatter = scatter!(ax, whale; markersize = 15, color = :orangered,
strokecolor=:white, strokewidth=1.5)
hidedecorations!(ax)
hidespines!(ax)
save("whale_init_point.png", fig) # hide
nothing # hide
m
````
![](whale_init_point.png)

Expand All @@ -104,4 +98,4 @@ set_theme!() # reset theme (default)

```@raw html
<video src="./whale_shark_128786.mp4" controls="controls" autoplay="autoplay"></video>
```
```
9 changes: 5 additions & 4 deletions src/map.jl
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ function Map(extent, extent_crs=wgs84;
provider=TileProviders.OpenStreetMap(:Mapnik),
crs=MapTiles.web_mercator,
cache_size_gb=5,
max_parallel_downloads=min(1, Threads.nthreads(:default) ÷ 3),
max_parallel_downloads=max(1, Threads.nthreads(:default) ÷ 3),
fetching_scheme=Halo2DTiling(),
max_zoom=TileProviders.max_zoom(provider),
max_plots=400,
Expand Down Expand Up @@ -187,24 +187,25 @@ function Map(extent, extent_crs=wgs84;
return map
end

function Base.wait(m::AbstractMap; time_out=10)
function Base.wait(m::AbstractMap; timeout=50)
# The download + plot loops need a screen to do their work!
if isnothing(Makie.getscreen(m.figure.scene))
screen = display(m.figure.scene)
end
screen = Makie.getscreen(m.figure.scene)
isnothing(screen) && error("No screen after display.")
wait(m.tiles)
wait(m.tiles; timeout=timeout)
start = time()
while true
tile_keys = Set(tile_key.((m.provider,), keys(m.current_tiles)))
if all(k -> haskey(m.plots, k), tile_keys)
break
end
if time() - start > time_out
if time() - start > timeout
@warn "Timeout waiting for all tiles to be plotted"
break
end
sleep(0.01)
end
return m
end
Expand Down
6 changes: 4 additions & 2 deletions src/tiles.jl
Original file line number Diff line number Diff line change
Expand Up @@ -54,17 +54,19 @@ function run_loop(thread_id, tile_queue, fetched_tiles, downloader, provider, do
end
end

function TileCache(provider; cache_size_gb=5, max_parallel_downloads=min(1, Threads.nthreads() ÷ 3))
function TileCache(provider; cache_size_gb=5, max_parallel_downloads=max(1, Threads.nthreads() ÷ 3))
TileFormat = get_tile_format(provider)
downloader = [get_downloader(provider) for i in 1:max_parallel_downloads]
fetched_tiles = LRU{String,TileFormat}(; maxsize=cache_size_gb * 10^9, by=Base.summarysize)
downloaded_tiles = Channel{Tuple{Tile,Union{Nothing, TileFormat}}}(Inf)
tile_queue = Channel{Tile}(Inf)
async = Threads.nthreads() <= 1

if async && max_parallel_downloads > 1
@warn "Multiple download threads are not supported with Threads.nthreads()==1, falling back to async. Start Julia with more threads for parallel downloads."
async = true
end
@assert max_parallel_downloads > 0
for thread in 1:max_parallel_downloads
if async
@async run_loop(thread, tile_queue, fetched_tiles, downloader, provider, downloaded_tiles)
Expand All @@ -88,7 +90,7 @@ function load_tile_data(::AbstractProvider, downloaded::AbstractVector{UInt8})
return FileIO.load(format) # this works because we have ImageIO loaded
end

function Base.wait(tiles::TileCache; timeout=10)
function Base.wait(tiles::TileCache; timeout=50)
# wait for all tiles to get downloaded
items = lock(tiles.tile_queue) do
copy(tiles.tile_queue.data)
Expand Down
2 changes: 1 addition & 1 deletion test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ using GeoInterface

# Default
london = Rect2f(-0.0921, 51.5, 0.04, 0.025)
m = Tyler.Map(london)
m = Tyler.Map(london); m.figure.scene
s = display(m) # waits until all tiles are displayed
@test isempty(m.tiles.tile_queue)
@test length(m.current_tiles) == 25
Expand Down

0 comments on commit 1e3bb98

Please sign in to comment.