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

Remove In[*] from cells when notebook is restarted #2460

Closed
dpsanders opened this issue Apr 30, 2017 · 17 comments
Closed

Remove In[*] from cells when notebook is restarted #2460

dpsanders opened this issue Apr 30, 2017 · 17 comments

Comments

@dpsanders
Copy link
Contributor

I often restart a notebook when a cell hangs.
If several cells were executed, they are all left with In[*] when the notebook is restarted, which can be confusing.

I suggest simply removing all occurrences of In[*] when the notebook is restarted.

@takluyver
Copy link
Member

That sounds reasonable to me, and should hopefully be easy to implement. I think you could just add a handler for the kernel_restarting.Kernel event.

@danagilliann
Copy link
Contributor

Hey! Can I try to tackle this issue?

@takluyver
Copy link
Member

Please do! Can you see what you might need to do? You'll probably want to search for the kernel_restarting.Kernel event in the Javascript code to see where it's fired and how other code uses it.

@danagilliann
Copy link
Contributor

Sweet! I'll probably get to this on Friday

@danagilliann
Copy link
Contributor

And I got to this much earlier than Friday. I'm looking into doing something here. Am I looking in the right place? If I am, does anyone have any suggestions on removing the In[*] instances?

@takluyver
Copy link
Member

The code that updates the In [ ]: prompts is in codecell.js - search for set_input_prompt

@danagilliann
Copy link
Contributor

I'm thinking of adding an if statement to determine if the notebook has been restarted somewhere here my only issue though is i'm not sure how to determine if the notebook had been restarted. I'm not sure if this is the way I should be going about this since i'm not sure if there is any data to tell me anything about that.

@takluyver
Copy link
Member

That code runs when the user executes a cell - I think the issue here is with restarting the kernel after that has happened.

I think the way to do this will be to handle the kernel_restarting event in codecell.js , in the bind_events method - i.e. add some code like this:

this.events.on('kernel_restarting.Kernel', function () {
that.save_widget.update_document_title();
knw.set_message(i18n.msg._("Restarting kernel"), 2000);
});

But inside the handler, if the prompt number is '*' set it back to nothing.

@danagilliann
Copy link
Contributor

Hi! I'm making some progress on the issue. I was able to write the event listener here. The issue I'm having now is that it doesn't seem to actually run when the event is triggered since nothing is logging to the console. Am I doing something wrong?

@takluyver
Copy link
Member

That looks right. Stick a console.log() above it to check that bind_events() is getting called for each code cell. 😕

@danagilliann
Copy link
Contributor

Hmm doesn't seem to calling it. I even tried running the debugger 😢

@takluyver
Copy link
Member

I just tried your branch, and when I restart the kernel, I do see KERNEL HAS RESTARTED in the Javascript console.

Are you rebuilding the Javascript after modifying it? The notebook doesn't load the separate js files directly - instead they're bundled into one big file to make it load quicker. There are instructions on how to work with this here: http://jupyter-notebook.readthedocs.io/en/stable/contributing.html#setting-up-a-development-environment

@danagilliann
Copy link
Contributor

danagilliann commented Apr 2, 2018

Hmm I did try that, but it's still not showing up for me. I even tried restarting the notebook. I'm just supposed to run jupyter notebook inside the repo for it to run in dev mode, right?

@takluyver
Copy link
Member

It doesn't matter where you run the command, but you need to do pip install -e . to do a development install, and then run npm run build (or setup.py js css, which is equivalent) each time you change it to rebuild the Javascript.

You might also need to hard refresh your browser a couple of times to make sure it's not loading the JS from cache.
`

@danagilliann
Copy link
Contributor

Argh. It's still not working and I also ran it in incognito mode :(

@takluyver
Copy link
Member

Possibly you're not running the copy of the notebook package that you've modified. This can be fiddly. Try these steps:

  • Uninstall all copies of the notebook package you can find
  • Run python -m pip install -e . in the notebook repository to install from there
  • Run npm run build to make sure the JS & CSS is up to date
  • Check that it's finding the version of the notebook you meant with python -c "import notebook; print(notebook)" (check the path it shows)
  • Launch with python -m notebook --port 8989 , and check that the browser is pointing to localhost:8989 (rather than the default 8888). This is just a random port that's not the default, there's nothing special about it.
  • Go to Help -> About in the notebook menus and check that the version number for the notebook server is a development version:

screenshot from 2018-04-03 10-33-32

@takluyver
Copy link
Member

Closed by #3494

@takluyver takluyver added this to the 5.5 milestone Apr 4, 2018
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Apr 13, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants