Skip to content
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

can I avoid initialization cells to be run on notebook load? #812

Closed
foice opened this issue Dec 2, 2016 · 6 comments · Fixed by #814 or zenotech/zCFDSuperBuild#99
Closed

can I avoid initialization cells to be run on notebook load? #812

foice opened this issue Dec 2, 2016 · 6 comments · Fixed by #814 or zenotech/zCFDSuperBuild#99

Comments

@foice
Copy link

foice commented Dec 2, 2016

I think init cells are a great thing, however the frontend sometimes needs to be reloaded for stupid reasons, which might have to do with javascript or anything else, but do not require to reload data from disk (for instance).

with the current extension, every time I re-load the page all the initialization cells are reloaded. is there a way to avoid this reload?

@jcb91
Copy link
Member

jcb91 commented Dec 2, 2016

currently, this isn't implemented, but it seems like a reasonable use-case for a configurable option. I think it's plausible to want this to be different in different notebooks, so worth storing in notebook metadata as well as in server's nbconfig.

@jcb91
Copy link
Member

jcb91 commented Dec 2, 2016

so, on closer inspection, this seems to stem from the fact that the initialization cells are simply run on the event kernel_ready.Kernel, which fires both when a new kernel becomes ready, but also when the frontend fires up & determines that a pre-existing kernel is ready. This also makes for some race conditions involving notebook & kernel load times, which could be better handled. I can't think offhand of a better way of determining whether it's appropriate to run initialization cells once the frontend boots, so I think I'll just implement my previous suggestion, of having a configurable parameter determining this behaviour, overrideable on a per-notebook basis in metadata.

@juhasch
Copy link
Member

juhasch commented Dec 2, 2016

I think it will be difficult to get consistent behavior of executing initialization cells only when a new kernel is started from the notebook frontend itself due to race conditions and the other things you mentioned.

You could check however for the kernel ID, which is unique for each restart. So the logic would be only execute the cell if the kernel ID has changed.

@jcb91
Copy link
Member

jcb91 commented Dec 2, 2016

You could check however for the kernel ID, which is unique for each restart. So the logic would be only execute the cell if the kernel ID has changed.

Neat, but we'd have no memory of whether the page has been loaded previously, so I think it'd still look like a 'new' kernel id. Unless we store it in local storage or something, perhaps. But, as you say, I think there are too many edge cases to expect that to work reliably.

@juhasch
Copy link
Member

juhasch commented Dec 2, 2016

There is no memory in Javascript that persists reloading as far as I understand, so you have to store it in notebook or cell metadata.
Another solution would be simply to do the initialization cells like:

if '_is_initialized'  is not in locals():
  _is_initialized = True
  # do my intialization

@jcb91
Copy link
Member

jcb91 commented Dec 2, 2016

There is no memory in Javascript that persists reloading as far as I understand

Well, there's window.localStorage as in select_keymap/main.js#L153, but even that's per-browser, so not really sufficient. I think your kernel-code is probably the neatest reasonably robust solution beyond only manually running them. Anyway, I've thrown together a PR to make the autorunning configurable on the basis that its default behaviour is just the same as what we have now anyway...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants