How to |
Stop a Computation
|There will be times when you want to stop Mathematica in the middle of a computation. You may have asked Mathematica to do something that you did not intend or that is taking too much time. Mathematica provides several convenient ways to stop computations, including menu items and commands that you can use in your programs.|
The menu items to stop or pause computations can be accessed from the menu:
To illustrate the stopping or pausing of computations, first set up a computation that takes some time to complete.
loop sequentially prints each integer from 1 to 1000, pausing for half a second at each step. It takes over ten minutes to finish:
To stop this computation, first select its cell bracket:
Then select from the menu:
then outputs $Aborted
If does not succeed in stopping the computation, you can do so by quitting the active kernel.
Select the kernel name from the menu. This menu item is located at the bottom of the menu. Here, is the name of the active kernel:
This stops all computations in the selected kernel. However, by quitting the kernel you will lose the results from your session, including definitions of variables and functions and output from computations. You should therefore use this with caution.
You must have a kernel running to perform computations. If you quit your only running kernel, you must start one again. To do this, simply evaluate any expression in a notebook, or select a kernel to start in the menu.
Here, kernel is restarted:
lets you momentarily pause a computation instead of completely stopping it. To do this, select the cell bracket of the running computation and then select from the menu:
You are then presented with a dialog box that lets you continue the evaluation, abort the evaluation, or start a kernel subsession within the interrupted evaluation:
Starting a kernel subsession lets you pause the computation and evaluate other expressions. This is very useful for checking on the status of variables in a long computation or for debugging.
also provides an alternative to using to enter a kernel subsession. With a computation running, select the cell bracket of the expression you want to evaluate and then select .
By selecting the brackets of more than one input cell and pressing Shift+Enter
lets you send several cells to the kernel for evaluation.
The cells are evaluated one by one. The bracket of each cell queued for evaluation thickens, indicating it is currently being evaluated or is in the evaluation queue:
To remove a cell from this evaluation queue, first select its bracket. Here, the queued cell is selected while the Do
loop continues to run:
Remove the selected cell from the evaluation queue by using from the menu:
You can also stop a computation by using Abort
as part of a Mathematica
Stop the evaluation of a sequence of commands:
Define a function for doing fixed-point iteration that aborts if the value gets above a certain limit:
Here, an unstable iteration is aborted:
This is a stable iteration that approximates the golden ratio: