Skip to content

v0.0.52 R01, before your first line

Choose a tag to compare

@tamnd tamnd released this 05 Sep 17:35
· 8 commits to main since this release
v0.0.52
e3eedf3

R01, the first of the nine runtime lessons, and a change of subject. Everything up to here has been about what happens when your code runs. This one is about what has already happened by the time it starts.

Eight cells, every one of them asking a child interpreter rather than the notebook, because a notebook has been up for minutes and cannot be a fair witness about its own startup. What is in sys.modules before your first line and where each of those modules came from. Every import that runs before your first line, with its own time. Seven children disagreeing about sys.flags.optimize. The whole path configuration with an exists check next to each entry. sys.path[0] compared across -c, a script, -m and -P. And ten timed starts of an interpreter that runs nothing at all.

The facts worth keeping. With site out of the way none of the startup modules were read from a file, because they are either C compiled into the binary or Python bytecode frozen into it. Startup is two halves on purpose and the first half has no import system, which is why a configuration mistake is a fatal error with a plain C string rather than a traceback. The command line and the environment settle a disagreement by taking the higher number rather than the nearer one, so PYTHONOPTIMIZE=2 survives a later -O. sys.path is produced by a Python program frozen into the binary and handed eleven C functions to stand in for the os.path it cannot import. And the front of sys.path is pushed on after startup is over, which is the whole mechanism behind a local random.py shadowing the standard library.

Two Tier 1 recordings, the first release against debug pair in the book. The debug build starts in 56.5 ms against 26.5 ms, and most of the extra is not the assertions. Release reports 17 frozen modules and none from a file. Debug reports 3 frozen and 14 from a file, because a debug build turns frozen modules off so that you can step through the real Lib/os.py. The import bill goes from 11.6 ms to 30.8 ms with it.

A new glossary group for startup and shutdown: two phase initialisation, path configuration, safe path. Six diagrams and sixteen citations. Both READMEs updated. GLOSSARY.md is 216 terms and CLAIMS.md is 564 claims across 72 lessons.