Skip to content

multimer: python -c is a batch entry; the timing ledger's follow-ups - #106

Merged
bdbarnett merged 2 commits into
mainfrom
fix/cpython-c-not-interactive
Sep 26, 2026
Merged

bdbarnett merged 2 commits into
mainfrom
fix/cpython-c-not-interactive

Conversation

@bdbarnett

@bdbarnett bdbarnett commented Sep 26, 2026 •

Copy link
Copy Markdown
Contributor

On CPython, python -c "..." that arms a timer before starting an app exits at once instead of running it. _hostloop.interactive() took any __main__ without __file__ for a bare prompt, and a -c one-liner has no __file__ either. The strategy came out ambient, App.run() returned immediately, and the process ended. -m and a script file were fine.

This consults batch() in the CPython branch, as the MicroPython branch already did, so -c gets the same none strategy as -m. _cmdline_tokens() also falls back to sys.orig_argv where there is no /proc (macOS), so the check works there too.

Found while proving the android-runner launcher on 0.6.1 (PyDevices/android-runner#24). Arming a timer at the top of python -c "...; import boot" made the launcher window open and the process exit in 0.2 s:

  • installed 0.6.1: boot returned ambient, exit status 0 after 0.2 s, the timer never fired
  • this branch: SMOKE_TIMER none, and the launcher runs until timeout stops it (status 124)

Tests: two new cases in tests/test_hostloop.py. test_cpython_dash_c_is_not_interactive fails on main and passes here. test_hostloop.py (20) and test_multimer*.py (36) pass with SDL_VIDEODRIVER=dummy.

A second commit updates the ledger (docs/timing-design.md, docs/timing-hardware-tests.md). The browser follow-ups pass: PyScript/Pyodide, and the rebuilt mp-wasm in PyDevices/PyDevices.github.io#9 and PyDevices/workbench#1. The runner's MULTIMER_BACKEND line goes in PyDevices/android-runner#24. The phone visual pass is still owed.

On CPython, interactive() treated any __main__ without __file__ as a
bare prompt, which includes python -c. So a timer armed at the top of a
-c one-liner chose the ambient strategy, App.run() returned at once and
the process exited, where -m and a script file keep the app running.
Consult batch() as the MicroPython branch already does, and let
_cmdline_tokens fall back to sys.orig_argv where there is no /proc.
@bdbarnett bdbarnett changed the title multimer: python -c is a batch entry, not an interactive prompt multimer: python -c is a batch entry; the timing ledger's follow-ups Sep 26, 2026
@bdbarnett
bdbarnett merged commit ecb9210 into main Sep 26, 2026
3 checks passed
@bdbarnett
bdbarnett deleted the fix/cpython-c-not-interactive branch September 26, 2026 13:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

1 participant