-
-
Notifications
You must be signed in to change notification settings - Fork 785
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Maximum call stack error when running pyodide within a web worker #441
Comments
@jstafford in your use of pyodide with webworkers have you come across this issue? |
Could this be related? emscripten-core/emscripten#5316 |
That issue within emscripten's archive talks about the use of "outlining" causes stack overflows within web workers.... ... If I understand correctly... |
@damaneice and I were digging into a problem that had the same behavior in jasoncharnes/run.rb#7 and tried a lot of different configurations. The reason this is happening has something to do with the |
I'm having a look through the following link to see what might be needed to port the current emscripten patches over: |
@SimonBiggs #480 is another attemps to rebuild for 1.38.35 to approach this more iteratively. Building just CPython does work, but there is an issue with actually loading pyodide that I'm still investigating. |
For me, Pyodide worker works in Chrome and Firefox (for both Windows 10/Mac 10.14), but I haven't tried loading any heavy packages. In Safari, I get a maximum call stack error as soon as I try to initialize Pyodide in a worker. I'm switching back to a non-worker solution... 😞 Thanks @SimonBiggs for reporting this issue. |
I am also getting this error on Safari (but not Chrome). Is there a way to catch it so I can fallback to non-web-worker Pyodide? |
I just hit this also. Still happens in safari 14.4 |
@joemarshall Did you get a fatal error now? How deep is the Python traceback vs the Javascript traceback? This info might help us set the Python recursion limit more appropriately. But the issue is probably unfixable on our side: Safari needs to give web workers a bigger call stack. A lot of Python code was written with the assumption that the recursion limit would be 1000, if it turns out the recursion limit is 50, it might be hard to get it to run. |
I got an error similar to the first screenshot in the issue in Chrome: when I imported one library it lead to a cascade of imports which went too deep. The solution for me was to first import the deeper library so that it didn't need to be imported again when I ran my actual import. Applying that idea above, you could import signal, then unittest, then numpy, then matplotlib. Of course none of that helps if you can't run any code in Safari at all. |
Thanks for the report! There is some related discussion in #1541 to measure and potentially decrease the stack frame size (to be able to do deeper recursions). |
In safari I got exactly 100 lines of trace, but given the top and bottom appear to be wasm functions, I think it may trim the stack trace down to 100 or something. I also didn't have a debug build to hand so no names (was on a student's Mac).
It reproduces in the linux webkit that is shipped with playwright though, so it is possible to debug on linux or WSL. Looks like mono has seen this too: |
When I first came across this thread it gave me the impression that Pyodide was completely unable to run any code in a Safari web worker, particularly this heavily liked comment:
Maybe that was the case at the time, but it doesn't seem to be any more. In particular https://github.com/dodona-edu/papyros has it working, including the ability to use some reasonably complex libraries. This is on Safari 14.1 so I don't think it's a change in Safari. Did something change in Pyodide to prevent these recursion errors? Having said that, we did find a place where some deep recursion happens in Pyodide itself which breaks Safari. Under the right conditions which I haven't quite figured out,
I suggest that in general pyodide should avoid using |
@alexmojaki Could you try with the 0.19.0a1 released yesterday?
Yes, I think the situation with Safari has been improving over time, particularly for 14.1 and later. |
It's not that easy to try, I only use Safari through Browserstack. It'd be great if Pyodide had an official demo of every version running in a web worker, even if it didn't support synchronous IO. Reproduction of that stack trace involves running But what I'm asking is what changed in Pyodide between those earlier comments and 0.18.1. At least from this thread none of the links seem to indicate a change. |
In 0.18.0 there was #1699 which increased the possible recursion depth, in 0.19.0 there are even more improvements in that area. See https://blog.pyodide.org/posts/function-pointer-cast-handling/ for more details.
Yes, we clearly need it. Related to #1498 |
System combinations that were tested, and confirmed bug occured:
Description of Bug
This issue appears to have been introduced when running Pyodide within a webworker.
Firefox
On Firefox I get the following error message:
Weirdly on Firefox on first page load it doesn't appear to occur, but after running a plain refresh
F5
this error message does occur.Chrome
On Chrome I get the following error message:
How issue was introduced
It occurs by including the line
ctx.pyodide.runPython('import matplotlib')
at the following location:https://github.com/pymedphys/pymedphys/blob/f6bdf5ce9e8858714d9f6c0fa629ce34d91e067b/app/src/observables/webworker-messaging/pyodide.worker#L39-L50
Demo of app causing issue
See a live version of this commit over at https://5ce927378b870500077d8c9c--app-pymedphys.netlify.com/
The text was updated successfully, but these errors were encountered: