![](https://seccdn.libravatar.org/avatar/a725014f091bcd9e8ff16e9f2a0d7e20.jpg?s=120&d=mm&r=g)
On Dienstag, 6. Oktober 2020 19:03:39 CEST Hans-Peter Jansen wrote:
[Intentionally disabled line wrapping for the strace snippets]
Hi,
While debugging an ugly segfaulting issue last week, I noticed something strange in the traces when comparing local builds with system builds (the ones, that were produced from OBS):
[...]
After opening the .pyc files, the interpreter always opens the .py files for the system package. For some reason, it doesn't accept the compiled files. The local package behave as expected.
The local files behave *differently*, but none is wrong, see: https://www.python.org/dev/peps/pep-0552/ The distribution pycs have both the 'hash_based' and 'check_source' flags set (5th byte == 0x3), so python has to read the original source to generate and verify the hash.
Needless to say, that this behavior is quite inefficient and not in the sense of the inventor. It would be even more efficient to to do without the compiled version and interpret every python file on load.
Is that to be expected?
Yes. Hashing the source is quite fast, much faster than generating the bytecode from scratch. Though, for pycs distributed along the sources, the 'check_source' flag is not strictly needed: "For hash-based pycs with the check_source unset, Python will simply load the pyc without checking the hash of the source file. The expectation in this case is that some external system (e.g., the local Linux distribution’s package manager) is responsible for keeping pycs up to date, so Python itself doesn’t have to check." Having the flag set is slightly paranoid, but not wrong per se. Kind regards, Stefan -- Stefan Brüns / Bergstraße 21 / 52062 Aachen home: +49 241 53809034 mobile: +49 151 50412019