Skip to content

MNT: be more careful about disk I/O failures when writing font cache #28541

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

Merged
merged 1 commit into from
Jul 12, 2024

Conversation

tacaswell
Copy link
Member

The locker works by writing a file to disk. This can also fail so make sure we can still import in that case.

Closes #28538

The only way I could think to test this is very synthetic and requires messing with the file system at in between importing the top level module and font_manager. Still not sure how the OP drove their system to expose this issue. I think it has not come up before because if the directory is not writable we detect that and bail to asking for a temporary directory to work with.

PR checklist

@tacaswell tacaswell added this to the v3.9.2 milestone Jul 11, 2024
Copy link
Member

@WeatherGod WeatherGod left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This makes sense to me. Are all file-related errors now OSError? Just double-checking.

@tacaswell
Copy link
Member Author

I checked the PermissionError is also an OSError and we were using OSError on the json dump line before.

@timhoffm
Copy link
Member

Are all file-related errors now OSError?

Yes. https://docs.python.org/3/library/exceptions.html#exception-hierarchy

Copy link
Member

@timhoffm timhoffm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Take or leave my suggestions. May self merge then.

# 2. import matplotlib which makes sure it exists
# 3. get the cache dir (where we check it is writable)
# 4. make it not writable
# 5. try to write into it via font manager
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
# 5. try to write into it via font manager
# 5. try to write into it via font manager
# 6. Check that we do not raise even though 5. cannot work

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Optional: Check that the log warning is emitted.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm going to pass on adding a check for the logging. I don't think we do that systematically currently and because the log emission happens in the sub-process it would take a fair amount of work to check (I think something like the tests for blocking where we print something and them search for the string in stdout).

The locker works by writing a file to disk.  This can also fail so make sure we
can still import in that case.

Closes matplotlib#28538
@tacaswell tacaswell force-pushed the mnt/morecareful_fontcache branch from ba06dc6 to 40f642f Compare July 12, 2024 02:19
@tacaswell
Copy link
Member Author

The windows failures were real, but fortunately we have hit them before and I could copy the fix (Python won't start on windows with an empty env because all of the random number APIs fail).

@tacaswell tacaswell merged commit 12cc509 into matplotlib:main Jul 12, 2024
44 checks passed
@tacaswell tacaswell deleted the mnt/morecareful_fontcache branch July 12, 2024 18:14
@tacaswell
Copy link
Member Author

Self merging per Tim's comment.

meeseeksmachine pushed a commit to meeseeksmachine/matplotlib that referenced this pull request Jul 12, 2024
QuLogic added a commit that referenced this pull request Jul 12, 2024
…541-on-v3.9.x

Backport PR #28541 on branch v3.9.x (MNT: be more careful about disk I/O failures when writing font cache)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Bug]: Permission denied when importing matplotlib.pyplot
3 participants