Repository navigation
Conversation
After the no-editable wheel install, launching Python from the repository root shadows the installed cypari2 extension with the source package. Start the two context tests from the tests directory so they import the installed wheel, matching CI.
dimpase
force-pushed
the
agent/cypari2-threadsafe-runtime
branch
from
September 30, 2026 02:54
2f03e7e to
18ce454
Compare
uv caches local directory packages using pyproject.toml metadata, so the persistent Darwin runner can install an older cypari2 wheel after a source-only change. Force a fresh project build before running tests.
Owner requests run under a snapshot of the submitting thread context, including reentrant Python callbacks. Correct the threading guide and cover concurrent callers with distinct ContextVar values. Co-authored-by: Codex <codex@openai.com>
The owner thread toggles this flag while signal handlers on other threads read it. Use the atomic type from cysignals rather than volatile sig_atomic_t, which only addresses signal access on one thread. Co-authored-by: Codex <codex@openai.com>
Document the fixed dispatch cost of small PARI operations and provide comparable measurements for main and this PR. The private owner-call cases isolate the round-trip overhead. Co-authored-by: Codex <codex@openai.com>
cxzhong
marked this pull request as ready for review
October 7, 2026 12:45
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.
Python thread-pool workers can enter libpari without an initialized PARI context and crash (#107). This change routes Python API operations that touch libpari through one permanent owner thread. Managed
Genvalues can then outlive the thread that produced them and be used or released by other Python threads.Calls from Python threads are serialized. Live stack values are moved to the owner's clone heap before a request completes, including values retained through callback side effects or exceptions. Python operator behavior and lazy iteration are preserved. Callbacks run in a snapshot of the submitting caller's
contextvarscontext and can make nested CyPari2 calls. PARI's native parallel computations remain available.Compatibility
Pari()no longer initializes the submitting thread's PARI stack. Move complete computations using rawGENvalues intopari.run_on_owner(function, *args, **kwargs), returning Python values or managedGenobjects. The existingnew_gen_from_doubleandnew_t_COMPLEX_from_doublehelpers dispatch automatically.sig_on()frame raiseRuntimeError; callers must leave that frame before submitting a request. Independent external cysignals-protected operations must not run concurrently with the owner.PariErroraborts the enclosing evaluation because PARI has reset its evaluator. Python callbacks in native PARI workers are rejected; usenbthreads = 1for those callbacks.spawnmethod, or fork before initialization. Descendants forked after initialization reject CyPari2 use, including after subsequent forks.Performance
Thread dispatch adds a fixed cost per request, which is substantial for small operations.
run_on_owner()provides a public batching entry point. The included benchmark compares small arithmetic, larger PARI calculations, and batched execution.Validation
Built and installed the wheel on Linux x86_64 with Python 3.14.4, PARI 2.17.3 (pthread), Cython 3.3.0, and cysignals 1.13.1.
make check: 2,493 doctests and 53 unit tests passed.git diff --checkpassed.Closes #107