How to print to stdout during code running in bootstrap.py?

Sorry if this is the wrong discussion group.

I’m working on this issue:
[wasm32-emscripten] Emscripten node build is not portable to windows · Issue #96509 · python/cpython (github.com)

And because of this problem:
Debugging node emscripten builds? - WebAssembly - Discussions on Python.org

I have to printf debug everything.

This works fine when the problem is in the c code, but I’m at the point where something is failing in bootstrap.py and I can’t just use ‘print’ because the builtins haven’t loaded yet.

Does anybody have any guidance on what I could use to print to stdout instead?

This is the error I get when using ‘print’ in bootstrap.py:

RuntimeError: lost sys.stdout

Ah, found it.

Using _verbose_message works if I launch with the -v flag.

2 Likes

Strange that it works, but maybe stderr is set but stdout isn’t.

Python sets an early stderr which is just enough to start Python, and quickly it’s replaced with a real class of the io module.