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.

os.path.exists crashes pyodide when using PROXYFS

See original GitHub issue

🐛 Bug

When file_path is in a directory that uses PROXYFS, running os.path.exists(file_path) returns True when the file exists but crashes pyodide when it does not.

To Reproduce

index.html:

<!DOCTYPE html>
<html>
    <body>
        <script> new Worker('webworker.js'); </script>
    </body>
</html>

webworker.js:

importScripts("https://cdn.jsdelivr.net/pyodide/v0.21.3/full/pyodide.js");

async function loadPyodideAndPackages() {
  self.pyodide1 = await loadPyodide();
  self.pyodide2 = await loadPyodide();

  await self.pyodide1.FS.mkdir("/dir1");
  await self.pyodide2.FS.mkdir("/dir2");
  await self.pyodide2.FS.mount(self.pyodide2.FS.filesystems.PROXYFS, {
    root: "/dir1",
    fs: self.pyodide1.FS
  }, "/dir2");

  // this code generates the expected output True False
  await self.pyodide1.runPython(`
import os

with open('/dir1/foo.txt', 'w') as f:
    f.write('hello')
print(os.path.exists('/dir1/foo.txt'));
print(os.path.exists('/dir1/bar.txt'));
`);

  
  // this code outputs True but then crashes on the last line
  await self.pyodide2.runPython(`
import os

print(os.path.exists('/dir2/foo.txt'));
print(os.path.exists('/dir2/bar.txt'));
`);

}

let pyodideReadyPromise = loadPyodideAndPackages();

The error message in the console is the following: Screenshot from 2022-10-11 21-24-11

Expected behavior

The code above should have produced the output

True
False
True
False

instead of crashing.

Environment

  • Pyodide Version: v0.21.3
  • Browser version: Chrome 105.0.5195.125, Firefox 105.0

Issue Analytics

  • State:open
  • Created a year ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
hoodmanecommented, Oct 12, 2022

Thanks for the report @omert. I believe that this is an upstream bug in Emscripten @scb100.

0reactions
ryanking13commented, Oct 12, 2022

I believe that this is an upstream bug in Emscripten @ scb100.

I think you mentioned the wrong person?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Python file existence checks loop crashes - unless I add a ...
If I step through the loop with a debugger, the code works fine, but if I just run the application, it crashes on...
Read more >
Release 0.21.3 unknown
Python code is run using the pyodide.runPython function. It takes as input a string of Python code. If the code ends in an...
Read more >
Failed to import skimage in a web-worker · Issue #917
After closing #253 with #866, we should be able to use scikit-image, however, when I try to import it (from cdn.jsdelivr.net/pyodide/dev/full/) ...
Read more >
Changelog — Python 3.11.1 documentation
gh-96192: Fix handling of bytes path-like objects in os.ismount() . ... The functions exist on the API by accident through inheritance and will...
Read more >
pytest Documentation
variable does not exist. Using monkeypatch both paths can be safely tested without impacting the running environment:.
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