Advertisement
Guest User

Untitled

a guest
May 20th, 2019
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.75 KB | None | 0 0
  1. #!/usr/bin/env python3
  2.  
  3. # usage: test_leak.py <image path>
  4.  
  5. import resource
  6. import sys
  7.  
  8. import pyvips
  9.  
  10. fname = sys.argv[1]
  11. out_path = "/tmp/test.tiff"
  12.  
  13. pyvips.cache_set_max(0)
  14.  
  15. for i in range(100):
  16. with open(fname, "rb") as fh:
  17. img = pyvips.Image.new_from_buffer(fh.read(), "", access="sequential")
  18.  
  19. kw = {
  20. "compression": "jpeg",
  21. "Q": 90,
  22. "tile": True,
  23. "tile_width": 256,
  24. "tile_height": 256,
  25. "pyramid": True,
  26. "bigtiff": True,
  27. }
  28.  
  29. img.tiffsave(out_path, **kw)
  30. print(f"[{i:03d}] Memory usage: {resource.getrusage(resource.RUSAGE_SELF).ru_maxrss}")
  31.  
  32. del(img)
  33. del(fh)
  34. del(kw)
  35. print(f"[END] Memory usage after freeing file handle and image: {resource.getrusage(resource.RUSAGE_SELF).ru_maxrss}")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement