Skip to content

Latest commit

 

History

History
101 lines (84 loc) · 5.56 KB

README.md

File metadata and controls

101 lines (84 loc) · 5.56 KB

native/

vispython/vispython.c defines the C ABI for embedded CPython. Entry points include vispython_initialize, vispython_version, vispython_eval, and vispython_exec. The ABI passes integers and NUL-terminated UTF-8 text. vispython_host_with_discard accepts a callback pointer. A null output buffer asks the callback to discard a reply that will not be retried. The legacy vispython_host does not send this notification. The bridge manages CPython references. The ABI does not pass PyObject * values to the host.

native/vispython/build.sh installs the CPython build pinned in .cpython-version into generated/prebuilds/<platform>/python/. It links the bridge against that interpreter. The archive keeps the bridge and interpreter tree together. Locations.pythonHome uses VIS_PYTHON_HOME when you set it to a nonblank path. Otherwise, it looks for python/ next to the library. The bridge passes this path to Py_InitializeFromConfig. With this layout and the default settings, the runtime uses the bundled standard library.

The release build uses CPython from astral-sh/python-build-standalone. The upstream project maintains that build, including security fixes. For local development, VIS_PYTHON_SYSTEM=1 ./native/vispython/build.sh links against the interpreter reported by python3-config or the PYTHON_CONFIG override. The result depends on that installation. Use the bundled build for distribution.

On macOS, use the bundled shared library. The upstream pgo+lto-full archives contain LLVM bitcode from a newer LTO toolchain than Apple's linker supports. The system toolchain cannot link libpython3.14.a from those archives. The bundled shared library needs no system Python.

Linux archives target Ubuntu 22.04 (glibc 2.35) on x64 and arm64. Release jobs build and test the bridge and worker on that baseline. They use a prebuilt CPython. Archive verification rejects any ELF file that requires a newer glibc version. This check includes CPython and its extension modules. A build on a newer distribution can add new symbol requirements without a change to the C source.

CPython remains a bundled shared library. Statically linking libpython would not remove glibc requirements from the bridge, worker or third-party extension modules; statically linking glibc is not a replacement for testing this dynamic-loading ABI. Consumers get the whole tree from the per-platform archive built with clojure -T:build platform-archive :platform <tag>.

Collect worker hang evidence

If a worker stops answering Python operations, request a private stack sample before terminating it. Configure stack sampling after initialization and before interpreter confinement. From the parent process, create a private directory. Set the code field of stack-diagnostics to an absolute path to a file that does not exist. On success, the worker creates an empty file with permissions no broader than 0600 and returns status: "ready". Setup adds no guest filesystem permission.

Request dump-stacks to collect a sample. Before writing, the worker checks that the descriptor still refers to the same file. A successful dump overwrites the file in place. The worker returns written, unavailable, busy, or failed, with a fixed reason where applicable. Send an empty stack-diagnostics path to close the retained descriptor. The worker can return busy without closing it. Normal worker connection shutdown also attempts to close it.

Stack collection uses no GIL or signals. It reads memory through the operating system instead of dereferencing live pointers. Concurrent thread or frame removal can leave an incomplete sample. Sampling supports release builds of CPython 3.14.7 with the GIL on macOS and Linux. Other builds, including Windows, return unavailable with reason unsupported-build. If the operating system denies the test read, the worker returns unavailable with reason memory-read-failed. Review the pinned private layouts before enabling stack collection for a new CPython version.

Each sample includes at most 64 threads, 64 frames per thread, and 100 code points per file or function name. It records definition lines and bytecode offsets, not current source lines. Names and paths can contain private information. Keep the file local. Review it before sharing. The file contains no source text or local values. It is separate from the diagnostic ring, which contains no payloads.

Set a deadline in the parent for the full control exchange, including socket writes. Disk I/O can stall. Retire the worker even if the sample is unavailable or incomplete. A sample is not a consistent debugger snapshot.

Windows x64

Install the Clojure CLI. Install the GraalVM CE version in .graalvm-version. From the repository root, run these commands in PowerShell 7.3 or newer in a Visual Studio x64 Native Tools environment:

./native/vispython/build.ps1
clojure -T:build javac
clojure -T:build worker-image
./scripts/test-windows.ps1
clojure -T:build platform-archive :platform windows-x64
./scripts/verify-platform-archive.ps1

The local archive contains vispython.dll, vis-python-worker.exe, a complete python/ tree, and python/Scripts/uv.exe. The Windows build uses checked-in SHA-256 pins for CPython and uv. The GraalVM CE setup action checks its download against a SHA-256 pin. Build with MSVC. MinGW and POSIX emulation are not part of the build. Run Windows tests locally; CI has no active Windows job.

Windows has no release archive. The source build targets x64 only. These instructions cover the Python runtime, not the Vis gateway, terminal, or workspace features on Windows.