_build_tables: Invalidate cache before importing generated modules #494
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Make sure to invalidate finder caches before trying to import generated modules. This is necessary according to the Python documentation: https://docs.python.org/3/library/importlib.html#importlib.invalidate_caches
This fixes a hard-to-reproduce bug that Python would be unable to find just-generated
lextab.py
if mtime of the current directory did not change from the moment the script was started. This could e.g. be the case if one has second-precision timestamps and removes the generated file just before starting the build, e.g.:It could also be reproduced easier by doing something like:
This is because the first command (
rm
ortouch
) updates the mtime of the directory to the current time. If the script is run fast enough, it manages to scan the directory and then write the newlextab.py
within the same second. As a result, mtime of the directory after writing the new file is the same as when the script was started, finder does not invalidate the cache and assumes thatlextab.py
does not exist since it did not exist when the directory was scanned earlier.This potentially fixes #493.
It was originally reported on https://bugs.gentoo.org/701878. Thanks to Gary E. Miller for patience in reproducing the problem and proxy-debugging it for me, as well as testing the final patch before submission.