I was recommended that I "kill the kernel" because my code would not function correctly in my computer even though it worked on my teacher's and he suggested before leaving that the code in memory was different than the one showing and that I should kill the kernel to see if it worked, but I searched and I can only find that the kernel is the core of my OS, so I don't know what that has to do with anything, since my code is pretty simple.
-
5Are you using jupyter notebook? There is an option in the jupyter user interface to kill the kernel. Probably what your teacher is referring to. I think kernel is just synonymous for the running python instance – BMW Jan 01 '21 at 21:04
-
Just close the terminal/console that you are currently using, and open a new one where you have not run that script yet. – SuperCiocia Jan 01 '21 at 21:39
2 Answers
Short Explaination
The Jupyter Kernel and the OS Kernel are not the same Read Here. Your instructor is right. You should restart your Jupyter Kernel if you are reusing variable names.
Long Explaination
So basically in jupyter notebooks you run your code in cells(blocks). Each block can be executed at different times instead of normal procedural(line-by-line) method. So often re-using a variable name and then running an old block can cause conflicts to it. For Example (Consider each newline to be a new cell in your notebook)
temp = 3 # First Cell -> We run this cell only once
temp = temp + 5 # We run this cell 2nd time without running the First cell
print(temp)
If we run all three blocks from start (first time) the end result is 8. But then if we run the 2nd cell again the result will be 13. This is a simple scenario where you can simply run the temp = 3 again and fix the code. But the real issue happens when you have large arrays or images stored in your variables. If your previous block hasn't processed the variables correctly and you run the next block with same variables you will get unpredicted result/errors.
So instead of going to each cell from above and starting to code. Simply choose the option

- 741
- 7
- 18
When I turn off a program on my computer, it deletes all the temporarily saved info and closed the program down. Killing the kernel does exactly that, but without turning off the front end.
Imagine you are using microsoft word and it freezes so you need to restart it. It closes the whole dang thing and then reopens it. If you could kill the kernel in word, it would be keeping the front end of word open, but just closing the backend.

- 310
- 1
- 8