-
-
Notifications
You must be signed in to change notification settings - Fork 2.4k
Closed as not planned
Closed as not planned
Copy link
Description
What did you do?
Call PIL.ImageGrab.grabclipboard() repeatedly.
What did you expect to happen?
A constant number of temp files to be created.
What actually happened?
The number of files in /tmp keeps increasing.
If there not an actual image in the clipboard, e.g. only text, then
xclip -selection clipboard -target image/png -outwill error with the message
Error: target image/png not available
while this error is caught on the latest Pillow (lines 146--148), the newly created tempfile is never removed.
Lines 146 to 151 in ab3d0c0
| if err: | |
| msg = f"{args[0]} error: {err.strip().decode()}" | |
| raise ChildProcessError(msg) | |
| im = Image.open(filepath) | |
| im.load() | |
| os.unlink(filepath) |
This can cause tempfiles to accumulate with repeated calls of grabclipboard().
I think os.unlink(filepath) should be called before ChildProcessError is raised to remove the now unnecessary file, i.e.
if err:
os.unlink(filepath)
msg = f"{args[0]} error: {err.strip().decode()}"
raise ChildProcessError(msg)
im = Image.open(filepath)
im.load()
os.unlink(filepath)What are your OS, Python and Pillow versions?
- OS: archlinux
- Python: 3.11.3
- Pillow: 9.5.0 (or commit ab3d0c0)