The asterisk next to a cell
[*] indicates that the cell is currently executing. While IPython provides each notebook with it’s own kernel, there is only one kernel per notebook. When that kernel is busy executing code (either a cell, or a series of cells) it cannot accept or run any further code until what it is currently doing is finished. New executions sit in a queue, until the kernel is ready.
If you wait long enough after trying to execute
2+2 you should find that it will eventually execute (assuming your main code ever exits).
The solution to this depends on your code, and how long you’re willing to wait to get the results. As a general rule try the following:
- Use a smaller data set to test the algorithm, then scale up gradually noting the increase in time. Is it going to be feasible with your full dataset?
- Is your algorithm reading/writing to the disk? Can you avoid it, or pre-load/post-save state?
- Is it possible to split your data into batches?
- If your algorithm is batchable, can you parallelize it to make best use of your CPU?
You can interrupt the kernel, however this will not work if the execution is currently out of the kernel’s hands e.g. in external C modules (a lot of
numpy for example). In these cases you may need to restart completely.
Get regular FAQs tips & tutorials direct to your Inbox.