Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle missing Python executable in ImageShow on macOS #6416

Merged
merged 3 commits into from
Jul 6, 2022

Conversation

bryant1410
Copy link
Contributor

There are exceptional cases in which sys.executable is empty or null (see the docs). I think it's better to just not delete the image in these cases, instead of crashing.

@radarhere
Copy link
Member

Just curious - did you figure this out because you are in an environment where sys.executable is None? What type of environment is that?

@bryant1410
Copy link
Contributor Author

Yes. I'm not sure how much details I can share, but it's kind of a custom way of running Python where the final program is compiled, so there's no Python interpreter anymore (AFAIK).

What about calling os.remove directly?

@radarhere
Copy link
Member

The subprocess doesn't just call os.remove, it also calls time.sleep(20). This behaviour started in #6010, so that the current Python process doesn't hang for 20 seconds. This period is intended to give time for Preview to open the image.

However, given that #6045 dropped removing the image altogether on Unix, the current form of this PR is not unreasonable.

@radarhere
Copy link
Member

I've created bryant1410#1 as a suggestion - if sys.executable is not available, how about falling back to python3 instead?

@bryant1410
Copy link
Contributor Author

bryant1410 commented Jul 5, 2022

Sounds good to me! It works locally. I merged it so it's here.

@hugovk hugovk merged commit 14b457e into python-pillow:main Jul 6, 2022
@radarhere radarhere changed the title Fix when sys.executable is empty or null Handle missing Python executable in ImageShow on macOS Jul 7, 2022
@beaux-riel
Copy link

I’m still experiencing the issue where the temporary file is deleted before Preview can open it on Mac. Has/will this be resolved?

@radarhere
Copy link
Member

This PR hasn't been released yet. It will be released as part of Pillow 9.3.0, due out towards the end of October.

However, it doesn't sound like you're experiencing the same problem. Are you saying that your images are taking longer than 20 seconds to open in Preview? Are they very large?

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.

4 participants