-
Notifications
You must be signed in to change notification settings - Fork 0
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
Enhancement idea - unthrowables #1
Comments
I think this package in it's current version is a bit obsolete because better functionality has been directly integrated into pyodide. I think this might be better as an issue on pyodide. Currently in pyodide I have patched in an interrupt into the main loop of ceval: I added it for every "slow dispatch" function, but like the rest of the CPython main loop maintenance stuff it is skipped by Another issue is integration with
Sounds like a useful thing to have. Again, you can set any one function like this with
My main concern is how you deal with situations where the native browser stack has stuff on it that can't be rewound. Do you have any way to inspect the stack for this and bail out if it's not going to work? It seems to me that it could really trash everything if the native stack and Python stack get out of sync (though I haven't thought very carefully about what sorts of problems you could see). I'd be much happier if we could raise an error "Stack could not be rewound" than if it fatally crashes pyodide. |
By the way, this unthrowables thing is really really cool! (But also scary dark magic.)
People really use repls / program on their phones? I guess they must, but it doesn't seem very pleasant. Of course the Safari on Mac issue is much simpler, it's probably possible to ask them to use Chrome or Firefox instead. |
I've done some work with exception unthrowing which allows doing roughly the same stuff with keyboard processing but without having to use shared memory - it instead throws an exception to jump right out to javascript and allows messages to come in before reconstructing the python stack to go back in where it was originally.
There are some disadvantages to my approach, most obviously that you can't interrupt in a with statement or in a try block that uses a finally, but on the plus side it doesn't require anything complicated in relation to server or browser side permissions, and maintains the javascript execution model nicely. I needed it because I have students who have iOS devices or use Safari on Mac, so they don't have shared memory support.
I think it would be nice to have these two complementary approaches integrated into pyodide_interrupts somehow. i.e. pyodide interrupts allowing:
a) Regular interrupt without throwing out
b) Regular interrupt that jumps right out to javascript where current python state can be resumed or cancelled.
c) On demand jump out to javascript with a parameter (I use this for things like doing time.sleep, and it could be used for doing synchronous IO in python when the underlying javascript is async), again current python stack can be resumed if wanted.
The code is all here
https://github.com/joemarshall/unthrow
and there's a demo on here:
https://joemarshall.github.io/websensors/pyodide/console_async.html
which is just a normal console, but you can do things like
and all should work and be interruptable with ctrl+c without killing the whole python state.
The text was updated successfully, but these errors were encountered: