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.

Pyodide doesn't recognize changes in files using the Emscripten File System API.

See original GitHub issue

🐛 Bug

When I’m using  pyodide.FS the method writeFile Pyodide doesn’t recognize changes in files.

To Reproduce

  1. Create a file using FS.writeFile, like this:
const content = `
def hello():
  return 'hello v1'
`;
pyodide.FS.writeFile('my_mod.py', content );
  1. Check the content by FS.readFile
const contentPy = pyodide.FS.readFile('my_mod.py');
const string = new TextDecoder().decode(contentPy);
console.log(string) // print content
  1. Now, execute code by runPython.
pyodide.runPython(`
    import my_mod
    print(my_mod.hello())
`);
  1. Check stdout, show the result:
hello v1

Here all fine!

  1. But, when I make any change in my_mod.py content with FS.writeFile Pyodide doesn’t recognize the changes. For example:
const newContent= `
def hello():
  return 'change'
`;
pyodide.FS.writeFile('my_mod.py', content );
pyodide.runPython(`
    import my_mod
    print(my_mod.hello())
`);
  1. Pyodide shows in stdout the old version file, check stdout:
hello v1
hello v1

Expected behavior

Pyodide should recognize changes in files using the Emscripten File System API.

Environment

  • Pyodide Version: 0.21.3

Additional context

I create a demo in this stackblitz project to explain the bug.

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:7 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
hoodmanecommented, Nov 6, 2022

This would probably be another good faq entry.

0reactions
nicobytescommented, Nov 6, 2022

@hoodmane great!

I tried your approach, which works here in my demo and now I have an idea for not running the 5 steps again.

The next week, I’ll send a PR with improvements in the docs. 🙂

Read more comments on GitHub >

github_iconTop Results From Across the Web

Accessing files does not work on Pyodide · Issue #2669 - GitHub
Inside the python code file, I access files locally given a directory ... save it to a virtual file system using Emscripten file...
Read more >
File System API — Emscripten 3.1.26-git (dev) documentation
Emscripten decides whether to include file system support automatically. Many programs don't need files, and file system support is not negligible in size,...
Read more >
Frequently Asked Questions — Version 0.21.3 - Pyodide
Why can't I load files from the local file system? How can I execute code in a custom namespace? How to detect that...
Read more >
faq.md.txt - Pyodide
Why can't I load files from the local file system? For security reasons JavaScript ... See {ref}`nativefs-api` for experimental local file system support....
Read more >
faq.md.txt - Pyodide
Why can't I load files from the local file system? ... Pyodide ``` More generally you can detect Python built with Emscripten (which...
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