Skip to content

Instantly share code, notes, and snippets.

@scossu
Created May 9, 2019 17:56
Show Gist options
  • Save scossu/cdde59337ff27f4436eafe23a61142b2 to your computer and use it in GitHub Desktop.
Save scossu/cdde59337ff27f4436eafe23a61142b2 to your computer and use it in GitHub Desktop.
#!/usr/bin/env python3
# usage: test_leak.py <image path>
import resource
import sys
import pyvips
fname = sys.argv[1]
out_path = "/tmp/test.tiff"
pyvips.cache_set_max(0)
for i in range(100):
with open(fname, "rb") as fh:
img = pyvips.Image.new_from_buffer(fh.read(), "", access="sequential")
kw = {
"compression": "jpeg",
"Q": 90,
"tile": True,
"tile_width": 256,
"tile_height": 256,
"pyramid": True,
"bigtiff": True,
}
img.tiffsave(out_path, **kw)
print(f"[{i:03d}] Memory usage: {resource.getrusage(resource.RUSAGE_SELF).ru_maxrss}")
del(img)
del(fh)
del(kw)
print(f"[END] Memory usage after freeing file handle and image: {resource.getrusage(resource.RUSAGE_SELF).ru_maxrss}")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment