-
Notifications
You must be signed in to change notification settings - Fork 38
Timing issue between importing dependency and making use of it #25
Comments
We need to see if there is a way to prevent the cell execution to continue until we are done with loading the links. |
FWIW, this problem exists (existed? we're not on 4.x line of code) in ipywidgets too. The scotch and omnibus demos both suffer from race conditions sometimes when run all is used. In that case, there's a race between the widget JS view finishing eval when echoed back to the notebook frontend in a |
Well, shouldn't the notebook just add the HTML/Javascript to the DOM and let the browser handle it? If it does, then I think Polymer would do the right thing (in this case). Of course, there are issues (mainly perf) with writing to the DOM cell-by-cell. Another approach may be to update the Notebook code to simply aggregate HTML/Javascript cells (in order) when going cell-by-cell, then do one DOM write at the end of the page. |
This one is starting to become a pain in demos where we have to inject arbitrary sleep statements (ugh) to ensure everything finishes bower installing in the back before code in the front tries to use it. I don't think it's solely related to bower install timing either: I've seen deployed dashboards fail to render properly because of the asynchronicity of having HTML linked assets hit the glass vs cell executions further down a notebook/dashboard page try to use them. In the notebook environment, here's an educated guess about why this seems to work sometimes and not others. Because the installs are happening synchronously (issue #43), the Tornado server remains blocked during a bower install and prevents messages from getting to the kernel by chance. But I think if you have more than one link import in a cell, those are done as separate AJAX requests from the frontend, so there are gaps that allow kernel execution requests which are queued up from the rest of the notebook to sneak through between the various bower installs. I thought about the following workaround: put one link tag per cell and only that link tag in the cell. It does make things a bit better, but it too has a subtle race condition. In this setup, you can't have later cell execution requests sneaking through between import calls. But you still have a race between the HTML getting echoed back to the frontend, the link logic trying to fetch the widget HTML (which doesn't exist), and the link import logic hitting the server import endpoint (which freezes further execution) to lock the kernel again. @lbustelo I'm open to brainstorming on this one. |
@parente Yes! Let's brainstorm today. A couple of things to consider.
Are for your guess of why it works on the notebook, I think you are spot on. And I suspect that once we find a fix #43, we will see the same problems in the notebook. Gino B.
|
Well, it doesn't work in the notebook today. The sleep is needed there too because of the execute leaks. The fix for #43 will make it worse because then there would be no blocking whatsoever. |
I guess I mean to say "sort of works!". I'm aware of the need for the sleep On Tue, Oct 20, 2015 at 7:48 AM, Peter Parente notifications@github.com
|
Yes. The sleep is a hack. The only correct fix is that the frontend load/execute has to sync with the backend execute/respond somehow. Let's chat this PM. |
Looks like this is specifically related to defining a Polymer element 'inline'. The recommendation there is to use |
Actually, use of |
Was the observation that the |
Tested this on a larger (non-test) notebook, which contains a Polymer definition similar to that of the test notebook attached in this issue. I (1) added When running in new container, server kicks off bower install of components. When done, some Polymer elements on the page load fine, but not our custom element defined in the page. Even re-running the cell doesn't show the element. Did But then I refresh the page and run all again and now the custom element loads fine and its toggle button functions normally. So |
With latest fix, I haven't seen any further issue with deployed dashboards after removing the hacky sleeps. The problem now only surfaces on the first Run All of a notebook that requires bower install as @jhpedemonte said. All signs point to the 404 -> install -> 200 trick as being the culprit but no concrete proof. Throwing this out there even though I don't think it'll work... What if on the first fetch attempt from the urth_components handler, instead of returning a 404 if the file does not exist, it runs off, does the bower install, and then completes the request? The browser then only sees a 200, albeit a slow one when the install needs to occur. Problem with this is how long will a browser wait before giving up on loading the target? |
404 -> install -> 200 trick won't work with the current implementation. We are currently overloading the link tag, so the initial request will just be for a file path (ie. I think the only way to do a 404 -> install -> 200 trick would be to create are own custom element and not overload the link tag. That way we could manage the initial lookup. Thoughts? |
To be clear, I was calling the current approach the 404 -> install -> 200 trick and saying that might be the culprit for the problem. So I must be missing what you're saying with "404 -> install -> 200 trick won't work with the current implementation." I thought it is the current impl? |
Sorry, meant we can't internally trap the first 404 on the server side and instead of returning the 404 to the browser, go ahead and bower install then return success. |
Stepping back, looks like the "install if it doesn't exist, load if it does" magic here might be impossible if we want things to work properly. (IMHO, working correctly every time is more important than magic. Reloads on bad wifi on Jupyter Day was painful because of this.) What if:
This separates the install from the use. It (hopefully) avoids the polymer getting confused because of the 404 hook (we think), perhaps even in case #3. And it's no different than the install-before-use requirement for dependences on the kernel-side (e.g., in Python yo have to pip install something, then import it, then use it; same with Scala, R, Julia, ...). |
With all the troubles that we've been having with extending the
Open questions:
Also, this |
Will this approach work with "Run all"? Is this what you had in mind with your open question? |
@jhpedemonte yes. Run all is the litmus test. |
Hypothesis: If there's exactly one import statement per cell, then it'll work. If there's multiple, then the server will free up between import calls and allow further queued cell execute requests to reach the kernel. If one of those queued requests is an Or not. This stuff is really hard to reason about, so it's probably worth trying it as an experiment and seeing what happens in practice. |
I'm failing to see how the "separate install from import" suggestion actually solves the run all problem. Seems like we'd still be in the situation of having to run an install cell prior to all the other cells. So that is no different then the current situation. |
It's been a few days, but I thought the point was to avoid the 404 -> install -> 200 problem screwing up polymer in a weird way. The import would still need to be made to block further code executions against the kernel somehow, yes. And I have no idea how to do that. |
Before I forget, my thinking on how to proceed after our last discussion:
|
@lbustelo and I took another look at this (the remote branch is here). We created an |
Let me elaborate a bit more on above...
The idea of this approach was to do the install work from the kernel to be able to sequence the work and block cell execution. What we did not account for was how |
The example notebook is working for me (with fixed href path of "urth_components/.....") on Chrome, Firefox and Safari on latest code with Polymer 1.3. |
I'm closing this issue. I think this works now as good as it can. The late stamping of |
Test notebook: https://gist.github.com/jhpedemonte/5193b20258742172778c
liveUpdate
istrue
).The text was updated successfully, but these errors were encountered: