question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Access to Emscripten's file system directly using Module.FS

See original GitHub issue

Feature

Access the Emscripten Filesystem directly instead of waiting for pyodide to initialise and be ready first.

Motivation

The Emscripten File system is provided by using the flag -s 'EXPORTED_RUNTIME_METHODS=["FS"]' when compiling C programs to WASM using emcc. This provides a direct access to the file system using Module.FS.

In case of pyodide however, because of the way it is compiled, the file system is accessible through pyodide.FS (which is just a re-export of Module.FS) or perhaps through pyodide._module.FS as mentioned here:

https://pyodide.org/en/latest/usage/file-system.html#dealing-with-the-file-system

While there is no difference apart from the way to access it, the side effect is of waiting for pyodide to be ready first.

Pitch

It would be nice to have access to Module.FS directly, which has the advantage of not waiting on the initialisation / startup time. One use-case could be fetching and setting up any additional non-pyodide specific files in parallel even before the runtime is ready.

Further, envisioning that more runtimes / interpreters (such as Micropython) will / are adopting WebAssembly, this provides a consistent way of accessing the File System across all such runtimes / interpreters.

Alternatives

This is just meant to initiate a discussion and perhaps there are better ways to think about this. And there might be some caveats in this approach which are being overlooked.

Additional context

Tagging some folks from PyScript here: @fpliger @antocuni @ntoll and from Pyodide as well: @hoodmane @rth

Issue Analytics

  • State:open
  • Created 10 months ago
  • Comments:10 (9 by maintainers)

github_iconTop GitHub Comments

2reactions
hoodmanecommented, Nov 22, 2022

It would be interesting to see if we could share one FS instance between multiple Pyodide instances. In a lot of ways that makes more sense than the current system. Either sharing the FS or allowing users to shut down and restart the interpreter might help all the people asking to reinstall / reload modules.

0reactions
antocunicommented, Nov 22, 2022

Well we removed global variables so that you can use loadPyodide multiple times. Each instance of Pyodide loaded in this way gets its own file system

oh, I wasn’t aware of that. I thought/assumed that the FS is a singleton ans it’s shared between the various emscripten “processes”. I agree, if the FS is per-pyodide, then my suggestions are non-sense, sorry for that 😃


+1 to make it possible to use Emscripten’s preRun, preInit hooks. As far as I understand that would address your use case, right?

yes, I think that given the other constraints this is probably the best way to solve our use case (although it makes the code on pyscript side a bit more complicated than what I would have liked, but too bad 😃).

Read more comments on GitHub >

github_iconTop Results From Across the Web

File System API — Emscripten 3.1.26-git (dev) documentation
This file system lets a program in node map directories (via a mount operation) on the host filesystem to directories in Emscripten's virtual...
Read more >
How to use FS? · Issue #854 · emscripten-core ... - GitHub
I tried to use the FS-API without success. I get an Uncaught ReferenceError: FS is not defined When i try to use it....
Read more >
How do I read a user-specified file in an emscripten compiled ...
I understand that emscripten doesn't support direct loading of files, but instead uses a virtual filesystem. Is there any way to load the...
Read more >
BrowserFS
There are all sorts of adapter file systems available to make it easy to access files stored in Emscripten, files stored in a...
Read more >
gravity-browserfs - npm
You can use any synchronous BrowserFS file systems with Emscripten! Persist particular folders in the Emscripten file system to localStorage , ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found