Skip to content

Conversation

@max-blau
Copy link

@max-blau max-blau commented Dec 9, 2025

The temp directory used store some downloaded bytes for fonts is sometimes not being cleaned up automatically via the __del__ dunder method. This commit exposes a cleanup method to allow users to handle this cleanup themselves if it affects their workflow.

tests:

➜ ~/work/fork/WeasyPrint (expose-font-cleanup-method) [weasyprint] $ pytest tests/test_fonts.py
================================================================================================================ test session starts ================================================================================================================
platform darwin -- Python 3.10.18, pytest-9.0.2, pluggy-1.6.0
rootdir: /Users/maxblau/work/fork/WeasyPrint
configfile: pyproject.toml
collected 8 items

tests/test_fonts.py ........                                                                                                                                                                                                                  [100%]

================================================================================================================= 8 passed in 0.14s =================================================================================================================

The temp directory used store some downloaded bytes for fonts is
sometimes not being cleaned up automatically via the __del__ dunder
method. This commit exposes a `cleanup` method to allow users to handle
this cleanup themselves if it affects their workflow.
@max-blau
Copy link
Author

max-blau commented Dec 9, 2025

@liZe I don't have permissions to add reviewers, here's a PR for the workaround we discussed in #2090

@max-blau max-blau closed this Dec 15, 2025
@liZe
Copy link
Member

liZe commented Dec 15, 2025

@max-blau Why did you close this pull request?

@max-blau
Copy link
Author

@liZe sorry, meant to post a comment.
It's not needed - you can just do something like this instead:

font_config = FontConfiguration()
del font_config

@max-blau max-blau reopened this Dec 16, 2025
@max-blau
Copy link
Author

@liZe nevermind - probably due to other implementation details in weasyprint, just subtracting the ref count of the FontConfiguration instance isn't enough to get the garbage collector to delete it.
Re-opening this - although its also possible to just call __del__ directly as a user - if thats OK with you, then this change could be dropped.

@liZe liZe added this to the 68.0 milestone Dec 28, 2025
@liZe
Copy link
Member

liZe commented Jan 2, 2026

Hi!

Thanks again for your pull request.

Re-opening this - although its also possible to just call __del__ directly as a user - if thats OK with you, then this change could be dropped.

I’ve spent some time trying to play with your pull request, and… I think you’re right.

No matter how hard we will try, there’s no reliable way to remove this folder because of how Fontconfig and Windows work, so even your test may fail if we actually use @font-face fonts in it.

And we don’t want to support and maintain public API that should be an implementation detail.

If you’re not on Windows, calling __del__ should reliably work, and that’s the best workaround in my opinion.

Sorry for taking so much time to come to this conclusion too 🙏, but I guess we had to go through these questions.

@liZe liZe closed this Jan 2, 2026
@liZe liZe removed this from the 68.0 milestone Jan 2, 2026
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.

2 participants