"""Start a kernel from source without writing __pycache__.
A script is compiled from source each time it starts; a module loads its
cached bytecode. The kernel is long, so this keeps about 4 MB of compile
work out of every kernel's memory.
With `--run
` the daemon starts this file directly: it leaves the
daemon's session and sends what it writes before its own output capture
starts to `/kernel.log`.
"""
import os
import sys
if sys.argv[1:2] == ["--run"]:
if os.getpgrp() != os.getpid():
os.setsid()
os.makedirs(sys.argv[2], mode=0o700, exist_ok=True)
log = os.open(
os.path.join(sys.argv[2], "kernel.log"),
os.O_WRONLY | os.O_CREAT | os.O_APPEND,
0o600,
)
os.dup2(log, 2)
os.close(log)
import albedo_cells # noqa: E402
albedo_cells.main()