Skip to content

Commit

Permalink
Fix memory leak.
Browse files Browse the repository at this point in the history
By switching to Image lib from imageio lib there does not seem to be a
memory leak.

I have done some testing and the image seems OK.

** More testing required ** I tested with images pulled from EC and
stored in files. It was not the full 3 hours of radar. Have not tried it
with HA either.
  • Loading branch information
gwww committed Jun 25, 2024
1 parent d2ea4cd commit b37745b
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions env_canada/ec_radar.py
Original file line number Diff line number Diff line change
Expand Up @@ -351,16 +351,18 @@ async def get_loop(self, fps=5):

def create_gif():
"""Assemble animated GIF."""
duration = 1000 / fps
gif_frames = [imageio.imread(f, mode="RGBA") for f in radar_layers]
gif_bytes = imageio.mimwrite(
imageio.RETURN_BYTES,
gif_frames,
duration = 1000 / 5
images = [Image.open(BytesIO(img)) for img in radar_layers]
gif = BytesIO()
images[0].save(
gif,
format="GIF",
save_all=True,
append_images=images[1:],
duration=duration,
subrectangles=True,
loop=0,
)
return gif_bytes
return gif.getvalue()

# Prime the cache - without this the tasks below each compete
# to load map/legend at the same time.
Expand Down

0 comments on commit b37745b

Please sign in to comment.