Flask backend for server-side Python execution#250
Merged
milanofthe merged 27 commits intomainfrom Feb 11, 2026
Merged
Conversation
Co-Authored-By: KDW1 <KDW1@users.noreply.github.com>
Co-Authored-By: KDW1 <KDW1@users.noreply.github.com>
Co-Authored-By: KDW1 <KDW1@users.noreply.github.com>
Co-Authored-By: KDW1 <KDW1@users.noreply.github.com>
Co-Authored-By: KDW1 <KDW1@users.noreply.github.com>
Co-Authored-By: KDW1 <KDW1@users.noreply.github.com>
Co-Authored-By: KDW1 <KDW1@users.noreply.github.com>
Co-Authored-By: KDW1 <KDW1@users.noreply.github.com>
Co-Authored-By: KDW1 <KDW1@users.noreply.github.com>
Co-Authored-By: KDW1 <KDW1@users.noreply.github.com>
- Migrate streaming from SSE to polling (start+poll pattern) - Fix stdin race condition with noop flush and leftover queue - Fix logging capture with permanent _ProtocolWriter on sys.stdout/stderr - Add recursion guard to _ProtocolWriter to prevent infinite loops - Fix ensureServerInit to retry on failure instead of caching rejection - Fix initBackendFromUrl to call init() for proper callback setup - Add resp.ok checks and poll response validation in FlaskBackend - Align stopStreaming to wait for server confirmation like Pyodide - Validate X-Session-ID header, return 400 when missing - Prevent orphan sessions in poll/exec/stop by using lookup instead of create - Move cleanup thread start into create_app factory - Fix requires-python to >=3.10 and add numpy dependency - Remove dead code: _capture_output, REQUEST_TIMEOUT, unused imports Co-Authored-By: KDW1 <KDW1@users.noreply.github.com>
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.
Adds a Flask/Waitress backend as an alternative to the Pyodide Web Worker for server-side Python execution. Useful for packages with native C extensions that aren't built for Emscripten.
Architecture
worker.py): REPL over stdin/stdout JSON lines. One per session. Handles exec, eval, and streaming with timeout watchdog (30s).app.py): Session management, routes translate HTTP into subprocess messages. Uses waitress in production, Flask dev server with--debug.venv.py): Workers run in a dedicated venv at~/.pathview/venv. Simulation packages install there, not in the user's environment.backend.ts): TypeScript client implementing the Backend interface. HTTP requests + long-polling for streaming.Key details
?backend=flask&host=http://localhost:5050PYTHON_PACKAGESindependencies.ts(same source of truth as Pyodide)pip install pathview→pathview servestream-execTesting