Closed magland closed 5 years ago
However, there is a problem with this, I am finding...
in jupyterlab, if I use the above hack to render the widget prior to the calculation, everything works, EXCEPT, the cell does not get marked as executed at the end. It still has the [*] indicator. This must have to do with the IPython.get_ipython().kernel.do_one_iteration() call. I wonder if there is a way around this, or if there is a different way to force rendering.
Another, more serious problem with the above "solution": the jupyterlab stop button does not work on the calculation once do_one_iteration() is called! Therefore, not a viable solution.
In my experience, unfortunately, sleeps and do_one_iteration just make async anomolies worse.
You cannot really "sync" between cell evaluation and widgets. This is because the IPython kernel sends messages to the widgets, but never waits for any replies (and there is no mechanism to make it wait).
However widgets are guaranteed to be initialized in order, so you can be guaranteed that the sequentially last widget will initialize last. I use that to implement the test helpers, for example:
https://github.com/AaronWatters/jp_proxy_widget/blob/master/jp_proxy_widget/notebook_test_helpers.py
Sadly this does not result in fully automated tests -- you still have to manually open the notebook and "run all".
Yeah, I read more of your tutorial, and can see why this is a necessary limitation. My workaround right now is to create the widget in one cell and then do the computation in another cell. It's working okay. You can close this issue if you want.
Watch out for "cell->run all" -- the widget in cell (1) will not execute until the computation in cell (2) finishes. This is a critical design flaw with Jupyter widgets in my opinion. Jupyter was not designed with widgets in mind.
You could hack around it by mediating all computation using widgets, I think. But that would be kind of weird.
This would be nice, but it's not possible in the current Jupyter infrastructure.
The following example shows real time update of a jp_proxy_widget showing the status of a computation
Suggestion: It would be great to have some API call on the widget that does the above... it could be something like
W.renderNow()
As indicated in the code above, yes, I could just do this in a separate call, but for my use case, this is not a good option.
I'm happy to try implementing this if that would be helpful.