Repository navigation
arisrvx: Python services beside the relay (S1) - #1081
Merged
Merged
Conversation
arisrvx is arisrv with an embedded CPython 3.12 (src/ariadne_python with its new server part). `arisrvx --python main.py [relay flags]` runs the operator's program on a script thread of its own with one asyncio loop, which serves its ASGI apps (pycvc.ariadne.serve_asgi, uvicorn). The relay never runs Python, never takes the GIL and never waits on the program (ARIADNE_SCRIPTING_HOSTS.md S1, section 6.5; reference ARIADNE.md 9.8). - ServerLink (server_link.h): the program's writes queue there, coalesced per path in the order of each path's last write, and the relay applies them at the top of each room step within --script-write-budget bytes (65536); the relay's events reach the loop through a waker thread that blocks without the GIL. - pycvc.ariadne (ariadne_server.py): Host (set, set_tree, set_series, get, get_tree, run, stop), serve_asgi, current_host. Built into arisrvx and imported at boot, so it needs no pycvc; also installed with pycvc as _pycvc_ariadne.py for plain python, where Host keeps its own tree. - Startup: the relay listens only once every ASGI app has started; a failed lifespan startup or bind stops arisrvx with 1 before it listens. uvicorn's sys.exit(3) on a failed startup is caught inside its task: raised from a task of its own it escapes the whole loop (risk 16's finding). - Stopping: on SIGTERM/SIGINT the relay keeps stepping while the program drains its servers (--shutdown-timeout, 10 s) and runs its apps' shutdown; its last writes go out, then the relay stops. host.stop(code) stops the relay with that status. uvicorn installs no signal handlers. - --http-listen ADDR:PORT serves the program's `app`; `arisrvx check main.py` runs it without serving and checks the --doc, the modules and the ports; `arisrvx python` is the interpreter. - A server document's python: block is refused in arisrvx (its functions would run on the relay's loop); stock arisrv refuses the Python flags and names arisrvx; the python token's message names arisrvx too. - cvcpkg/recipes/arisrvx (Linux), its publish step beside arix's, and the pycvc-linux CI job builds and runs it (WebSocket transport on, the cp312 FastAPI stack installed). Tests: ServerLinkTest; arisrvx_serve, _program, _http_listen, _startup_fails, _check, _check_missing_module, _doc_python_refused, _python_interpreter; arisrv_python_needs_arisrvx; pycvc_ariadne_server.
…s' shutdown; 3.7.13 ServerLink::wait_finished replaces end_script's wait_start loop, which returned at once once the program was past startup. The ASGI servers get 2 s past --shutdown-timeout for their apps' shutdown, inside the 5 s grace before arisrvx gives up on the program. The recipe and the test documents follow master's 3.7.13 bump.
arisrv's main.cpp uses the gRPC state and media transports whatever else is on, so a WebSocket-only libcvc configured arisrv but could not link it (undefined state_transport_grpc, stream_transport_grpc, stream_relay). The job now installs grpc and protobuf in a prefix of its own, as package-linux's enable_grpc lanes do, and turns CVC_ENABLE_GRPC on beside CVC_ENABLE_WS.
Conflicts kept both sides: the python token names arix, ariglx or arisrvx and the new wasm one arix or ariglx (arisrvx gets no wasm engine); the roadmap's status lists S1 with P1b and G1; the engine's header comment says both. The server part is unchanged on Python's ScriptEngine: a server host's attach still gives its document's runtime no Python engine, only the hook that refuses a python: block, and it includes loader.h itself now that the engine no longer does.
Master's test (#1077) compared one agent's position. scatter_free's draw differs between standard libraries, and on macOS that agent stays where it began under both policies, so the macOS recipe and package legs fail here. This is the same hunk as open #1095, so merging master once #1095 lands is clean.
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.
S1 of the scripting-hosts application-services cut (
docs/roadmap/ARIADNE_SCRIPTING_HOSTS.md§6.5 and the S1 row in §10). It builds on S0 (#1046) and P1's engine (#985, #1000).arisrvxis arisrv with an embedded CPython 3.12.arisrvx --python main.py [relay flags]runs the operator's program beside the relay, on a script thread of its own with one asyncio loop. That loop serves the program's ASGI apps (FastAPI on uvicorn). The relay never runs Python, never takes the GIL, and never waits on the program. The reference is the new ARIADNE.md §9.8.Risk 16, tested first
Tested on cvcpkg's python312 3.12.10 with uvicorn 0.53.0, FastAPI 0.141.1 and Starlette 1.7.0. Windows was tested here; Linux runs in this PR's CI.
Server.serve()installs no signal handlers: SIGINT, SIGTERM, SIGBREAK and the wakeup fd are untouched.sys.exit(3). Whenserve()is a task of its own, asyncio re-raises that SystemExit out of the loop, and every other task on it dies too.serve_asgicatches it inside the task's own coroutine. Recorded under risk 16 in §9.What's in it
ServerLink(src/ariadne_python/server_link.h) sits between the script thread and the relay. The program's writes queue there, coalesced per path in the order of each path's last write (a section's fields, then itsrev). The relay applies them at the top of each room step, ahead of the server document, within--script-write-budgetbytes (65536 by default).set_treewrites the way(state-set-tree)does. The relay's events reach the loop through a Python waker thread that blocks without the GIL.pycvc.ariadne(src/ariadne_python/ariadne_server.py) holdsHost(set,set_tree,set_series,get*,get_tree,run,stop,loop),serve_asgiandcurrent_host._pycvc_ariadne.py, and pycvc's import registers it aspycvc.ariadne. Under plainpythonthe same program runs, withHostkeeping its own tree.--shutdown-timeout(10 s) and runs its app's shutdown. The program's last writes go out, and then the relay stops.host.stop(code)stops the relay with that status.--http-listen ADDR:PORTserves the program'sappfor a program that doesn't callserve_asgi.arisrvx check main.py [relay flags]loads the--doc(itsrequires:) and runs the program without serving. It reports missing modules, an--http-listenwith noapp, and ports that are taken.arisrvx pythonis the embedded interpreter as a plain python3.cvcpkg/recipes/arisrvx(Linux). Its publish step sits beside arix's inpublish-cvcpkg.ymland runstests/program.pybeside a relay before it packs.fastapi-cp312anduvicorn-cp312, and runs the arisrvx tests with the scripting-host ones.Flagged for review
python:block is refused in arisrvx, not run. Its functions would be called from the document's programs on the relay's loop (§6.2). I moved it to S2, where exports run on the script thread.--script-slow-msmoved to S2. The warning names a sync export, and exports are S2's.pycvc.ariadneis built into arisrvx and also ships with pycvc. In arisrvx the built-in copy always wins: pycvc's import leaves an existingpycvc.ariadnealone.server: publish:), so a Python-only service runs with a--docthat publishes its namespace. S7's end-to-end test may want a way to publish from Python.requires: [python]on a stock host now names arix, ariglx or arisrvx.Tests
Local, on Windows (static Release, gRPC + WebSocket):
ServerLinkTest(11 cases);arisrvx_*ctests:serve,program,http_listen,startup_fails,check,check_missing_module,doc_python_refused,python_interpreter;arisrv_python_needs_arisrvx;arisrv_*,ari_server_*andAriadneRequirestests.That is 52/52.
test_pycvc_ariadne_server.pypassed against a stand-in pycvc; with the real pycvc it runs in CI's pycvc-linux job.