Skip to content

Conversation

@mconst
Copy link
Contributor

@mconst mconst commented May 24, 2021

First of all, thanks for maintaining Pillow all these years!

When Image.show() displays an image on Linux using eog, there's a race condition where the file can get deleted before eog opens it.

To reproduce this, you'll need a Linux system without imagemagick or graphicsmagick installed. Then you can make it happen pretty reliably, just by calling Image.show() several times:

from PIL import Image

im = Image.new('RGB', (400, 300), 'green')

for i in range(4):
    im.show()

With imagemagick installed, this correctly displays four green boxes. But if you're using eog, usually several of the images will give error messages like "No images found in file:///tmp/tmprt8btbpr.PNG" instead.

This happens because Image.show() expects its display command to run synchronously, but in fact eog runs asynchronously if another eog instance is already running -- it just asks the other instance to open the file and then immediately exits. The fix is to use eog -n instead, which forces it to always start a new instance.

Image.show() expects its display command to run synchronously, but eog
is asynchronous if there's another instance already running -- it just
asks the other instance to open the file and then immediately exits.
This causes intermittent failures where the file gets deleted before
the running eog instance manages to open it.

Fix this by using the -n option, so eog starts a new instance each time
instead of trying to reuse an existing one.
@radarhere radarhere merged commit 10d8800 into python-pillow:master May 25, 2021
@radarhere
Copy link
Member

Good work for figuring out this solution.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants