Skip to content

Conversation

@KDW1
Copy link

@KDW1 KDW1 commented Jan 21, 2026

Added an alternative setting for the PathView application so that you can either use Pyodide web assembly or send client-side fetch requests to a Flask web server that has execution, evaluation, and traceback routes (the initialization code of the server borrows from the init() function found in worker.ts.

Major Changes:

  • Added a backendPreferenceStore which is nearly identical in form to themeStore since it switches between two binary values. It is binded to 'Q' (arbitrarily so), and toggling it calls switchBackend(preference : BackendPreference) from backend.ts
  • The backendPreferenceStore is accessed from backend.ts and passed in as an event parameter sent along with the "init" message posted to the worker. This sets the backendPreference for said worker
  • Every function within worker.ts that previously called await pyodide.runPythonAsync(...) now has a fetch request counterpart, such that the Flask backend route is shallow copy of what pyodide was doing

Current issues:

  • It seems like we're running multiple excess requests due to an error Scope: 'NoneType' object is not iterable which comes from the generateStreamingStartCode() function in pythonHelpers.ts, specifically the find_scopes() funciton

KDW1 added 21 commits January 14, 2026 11:38
…lp me identify what routes to replace with the Flask alternative
…ven't implemented nay backend changes), also added backendpref store and structure
…eyboard shortcuts, currently working on modifying handleRun and handleContinue
… out what other data structures (like nodeRegistry and some of the python generation code) I need to convert
…out how to replicate the validateGraphBridge() functionality
…imply redirect pyodide execution requests to the web server!
… -> Pyodide backend -> workers in order to avoid accessing localStorage from the level of the workers in the Pyodide backend
…he store, instead of the value being passed down! Also identified where the rror is thrown about a owrker not being initialized
… seem to have finished eval and exec. Trying to figure out how to run streaming with flask now
@RemDelaporteMathurin RemDelaporteMathurin changed the title Merging flask-backend branch into pathsim Adding a Flask backend Jan 21, 2026
@KDW1
Copy link
Author

KDW1 commented Jan 21, 2026

TODOS

  • Review the requirements for handleRun() in the main index page for the SvelteKit application, in terms of whether simulation is running or not, etc...
  • Fix the issue where the Flask version doesn't interact with the console's stdout and stderror
  • Fix the Scope: 'NoneType' object is not iterable error, which is most likely connected to the excess api calls!
  • Finish pull request description

@milanofthe
Copy link
Member

@KDW1 good start, basic exec/eval works and the toggle UI is there. But there are some architectural issues preventing this from working properly.

Worker imports stores:
Workers run in a separate thread and can't access main thread state. This is why you hit the localStorage/window errors. The typeof window === 'undefined' check masks it but doesn't fix it. Workers must be self-contained, pass state via postMessage.

Flask inside PyodideBackend:
The Backend interface exists so we can swap implementations cleanly. Flask shouldn't be a flag inside PyodideBackend, it should be its own FlaskBackend class implementing the same interface. No worker needed for Flask, just fetch calls from main thread.

Streaming broken:
This is why Scope returns (None, None) or partial data. The pyodide streaming works because the generator _streamer lives in the worker and maintains state between steps. With Flask each HTTP request is independent - the generator state doesn't persist reliably across requests. For Flask streaming you'd need SSE/WebSocket.

Minor:
Typo reosurces in backend.py CORS config, requirements.txt lists stdlib modules (gc, io, contextlib) which will fail pip install.

Suggestion:
Create a FlaskBackend class, remove store imports from worker.ts. Read the readme for the architecture. Or just copy it into chatgpt.

@KDW1
Copy link
Author

KDW1 commented Jan 23, 2026

Thank you for the help Milan. I appreciate the direction. I'll be sure to work on a separate Flask Backend class in backend.ts and address the rest of the issues. Thank you!

@KDW1
Copy link
Author

KDW1 commented Jan 23, 2026

TODOS (After Review)

  • Create FlaskBackend class
  • Remove store imports and flask alternatives in worker.ts to be completely removed from the flask backend class
  • Work on an api route that focus on the Flask API streaming the data with SSE
  • Fix the resources typo

KDW1 added 2 commits January 23, 2026 09:34
…-backend

Updating flask-backend branch of my fork with the most recent changes to main in the original repository
KDW1 added 8 commits January 23, 2026 09:50
…tion. Still need to implement basic streaming option and also work on removing the flask snippets that remain in worker.ts
… a separate Flask Backend class, now I just need to begin working on Flask streaming and removing the Flask code from worker.ts
…ng logic within a single api request and then stream the resulting data!
…is working out but I need to work on fetching those results
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants