-
Notifications
You must be signed in to change notification settings - Fork 64
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
Proposal: javascript thread with callback #243
Comments
Thanks for opening an issue :) I just gave
Now back to your original suggestion, I made some attempts in the past to allow running animation loops in the front-end (if that's what you want), see https://github.com/martinRenou/ipycanvas/pull/75. But that was a bit too complicated and I decided to keep the library simple. Would you be able to provide a code sample that shows what you're trying to do with ipycanvas? I might be able to suggest some tricks to make it more efficient. |
Somewhere during initialization call in CanvasView in widgets.ts:
This will set a recurring timer. Catch the timer and then make a callback to python.
On the python side, it would look something like this:
Then the tick handler could look like this, pushing the image every tick:
(Or whatever canvas draw calls). This way there will only be one thread on the front-end. It will be slower than two threads, but hopefully gets around whatever google colab is doing to interfere with multi-threading. |
ipycanvas struggles with threading in Google Colab notebooks and the threading examples don't behave properly. To mitigate, and perhaps for other reasons, it would be useful to have a thread running on the javascript side of things at a particular framerate and posting callbacks to be caught on the python side. That way, the python side will not need run multiple threads. This does seem to only be a problem with Google Colab notebooks, however. (Why Google Colab? I'd like to be able to use Google's free GPUs to train neural networks that interact with pygame via ipycanvas.) Thanks for considering my weird request!
The text was updated successfully, but these errors were encountered: