Repository navigation
Device: run inside PyUI's process instead of launch.sh - #29
Merged
Merged
Conversation
Opening Cheevos used to make PyUI exit so principal.sh could run
launch.sh, which started a second Python, brought up its own PyUI for
the platform, and left PyUI to start again from scratch on the way
back. With spruceUI/spruceOS#NNNN, PyUI runs the app in its own process
instead: config.json names an entry point ("pyuiEntry":
"cheevos.native:run"), PyUI calls it from the Apps menu, or with
game_id from the game menu's "View achievement progress", and unloads
every module from App/Cheevos when it returns.
- Add cheevos.native: run() logs to the app's own log and turns an
error into a message; session() takes out everything the app puts
into PyUI (texture budget, log redaction factory), waits for the
cheevos-* workers, and copies the API key to Spruce's setting.
- Add ui/pyui/host.py for what a session asks of PyUI. Spruce's Web
API Key setting is now changed through PyUI's CfwSystemConfig:
launch.sh's jq edit would be overwritten by PyUI's copy in memory.
- Remove launch.sh, cheevos/__main__.py, platform/arguments.py and
ui/pyui/bootstrap.py, with its device workarounds (Wi-Fi status
warm-up, the Mini's backlight helper, our own PyUI state file). The
desktop runner's PyUI start-up moves to
platform/desktop/pyui_setup.py.
- make launch [GAME=id] opens Cheevos on a device the way the menus
do: scripts/device_session.py (dev only, not packaged) restarts with
the running PyUI's environment and calls PyUI's own runner.
- CI's spruceos job refuses to open the mirror PR until the target
branch has PyUI's runner (App/PyUI/main-ui/apps/native_app.py).
- tests/screens/test_native_sessions.py runs two sessions in a desktop
PyUI and checks that no Cheevos module, object, thread or hook is
left behind.
On a Miyoo Mini Plus, Cheevos opens in about 0.5 s and closes in about
0.1 s. After closing, PyUI keeps 6-7 MB more, which stayed flat over
six sessions.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Why
Opening Cheevos made PyUI exit so
principal.shcould runlaunch.sh. That started a second Python and brought up a PyUI of Cheevos's own: display, theme and controller. When you closed it, PyUI started again from scratch. That's two PyUI start-ups per visit.launch.shalso had to copyApp/PyUI/launch.sh's per-platform set-up (SDL libraries, drivers, device names), and our bootstrap carried workarounds for things PyUI only does in its own launcher.spruceUI/spruceOS#1949 lets PyUI run an app inside its own process, like the Activity Tracker. Cheevos now opens from the menu that's already running and hands it back when it closes.
What changed
Entry point.
config.jsonhas"pyuiEntry": "cheevos.native:run"instead of"launch". PyUI importscheevos.nativefromApp/Cheevosand callsrun()from the Apps menu, orrun(game_id=N)for "View achievement progress", where B goes straight back to the game menu. Whenrun()returns, PyUI drops every module loaded from the app's folder.Leaving nothing behind. Unloading only frees memory if nothing in PyUI still refers to Cheevos, so
native.session()takes out everything the app put in, in reverse order:cheevos-*workers, which get 2 s to finish.The app logs to
Saves/spruce/cheevos-<platform>.logthrough its own handler, without propagating, so its records don't mix with PyUI's. An error is logged, then shown as "Cheevos stopped after an error. Details: " for 5 s, and you're back in Spruce's menu. If Cheevos can't even be imported, PyUI shows "The app stopped after an error." and logs it topyui.log.Spruce's Web API Key. The key is copied to that setting through PyUI's
CfwSystemConfig(ui/pyui/host.py).launch.shedited the file with jq, which PyUI, holding the settings in memory, would now overwrite.Removed.
launch.sh,cheevos/__main__.py,platform/arguments.py,ui/pyui/bootstrap.pyand their tests. The device workarounds go with them, since PyUI's menus already do these: the Wi-Fi status warm-up, the Mini's backlight helper, and our ownpyui-state.json. The desktop runner's PyUI start-up moved toplatform/desktop/pyui_setup.py, which isn't packaged. The package now has no PyUI start-up code at all.Dev launcher.
make launch [GAME=<id>]opens Cheevos on a device the way the menus do, without tapping through them.device.shsaves the running PyUI's environment and command line from/proc, then asks it to exit.principal.shrunsscripts/device_session.pywith PyUI's own interpreter, which restarts itself with that environment, brings PyUI up asmainui.pydoes, and calls PyUI'snative_app.run. Nothing is per-platform.make stopcloses it, andDEVICE_PYTHON_FLAGSpasses flags such as-X importtime.Release pipeline. Cheevos without
launch.shneeds PyUI's runner, so thespruceosjob checks the target branch forApp/PyUI/main-ui/apps/native_app.py. It fails without opening a PR until that's merged; rerun the job afterwards (RELEASING.md).Also changed
/tmp/cheevosscratch folder is removed on exit..agents/pyui.md("In-process sessions"),device.md,integration.md,product.md, TESTING.md, RELEASING.md, and the wiki's Installation and Troubleshooting pages.Testing
make checkpasses (1,098 tests).tests/screens/test_native_sessions.pyruns two sessions back to back in a desktop PyUI, unloads Cheevos as PyUI does, and checks that no Cheevos module, object, thread or PyUI hook is left.tests/unit/test_native.pycovers errors, the log handler, the clean-up order, the key copy, the workers and the redaction.On devices, with the matching Spruce change:
make launch/make launch GAME=519. It opens in about 0.5 s and is back in the menu in about 0.1 s; the first open after an update takes about 3 s while Python compiles the bytecode. While open, it uses the same memory as the old separate process. After closing, PyUI keeps 6–7 MB more (Python's allocators hold freed memory for reuse), flat over six sessions in a row, and PyUI's restart before every game gives it back.Merge spruceUI/spruceOS#NNNN first.