-
Notifications
You must be signed in to change notification settings - Fork 83
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
Add support for getters #587
Conversation
Check out this pull request on See visual diffs & provide feedback on Jupyter Notebooks. Powered by ReviewNB |
c4df265
to
dd42dbf
Compare
9a35f4e
to
42f05fa
Compare
itkwidgets/viewer.py
Outdated
if 'getImageInterpolationEnabled' not in self.results: | ||
self.call_getter('getImageInterpolationEnabled') | ||
elif self.results['getImageInterpolationEnabled'].done(): | ||
return self.results.pop('getImageInterpolationEnabled').result() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we put this sequence of calls in a decorator?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yup, updated!
This approach is making progress but is still a bit naive and has a lot of additional cases/needs to take into account. Starting a list here of key concerns and shortcomings so that they are addressed as this moves forward:
|
Todos
which should help with all three points above. -> merge Create another issue as needed for setting cell output with a getter output. |
@bnmajor this timeout only occurs when the tests are executed through nbmake? @alex-treebeard are notebook events processed in a different way when executed through nbmake? |
@alex-treebeard suggested that there may be a to resolve via the way nbmake uses nbclient. |
@thewtex So it seems like the |
@thewtex been doing a bit of reading around widgets. Is it necessary to load the browser in order to initialise the ITK widget? What needs to run in order to unblock the getters from executing against an initialised viewer object? |
It is not necessary to import and run the Python code. However, a browser is necessary for the graphical context and JavaScript environment to perform renderings and work with the client-side widget state.
One way or another, we need to be talking to, e.g., Chrome / Electron in Headless Mode, when running in nbmake / nbclient. |
@alex-treebeard great idea!! Yes, we could use a version of |
Getters are designed with the expectation that they will be called twice. On the first pass the getter is added to a queue and a callback function is set on each. Once the getter resolves the result is set in the results dict and getters are ready to be called again to return their result.
This allows us to grab the cell id and raw cell string for re-running cells with getters.
Intercept execute_requests (which will be all cells queued to run after the Viewer class has been instantiated. Once the itk_viewer has been created the queue is processed one request at a time. If a cell contains getters, futures are created for each and a callback function is set to set the result as they resolve. Once all of the results are set the cell is run and the queue continues to be processed.
If we have a current request when the queue is empty we still need to execute that cell.
Let's merge this, then, in separate PR's
|
Improved testing is a current work in progress (as discussed in issue InsightSoftwareConsortium#587). Until we resolve the outstanding issues no viewer is actually being created, so the queue that waits for cell completion before progressing causes all subsequent cells after the first viewer is created to fail. This temporarily ignores those cells in the CI tests. These changes should be removed after testing is fixed.
-- WIP --
Guided by the items discussed in #568 this branch attempts to add support for getter functions. Adapting approaches in the ipython_blocking and jupyter-ui-poll libraries the general approach is to:
execute_next_request
to start the cycle of processing the remaining cellsIssues: