11
$\begingroup$

Is it possible to pause an already running evaluation that takes a lot of time? And then continue it later?

I can suspend my computer, but that's not what I want. I would like to use my computer in between without it being noisy due to heavy CPU usage by Mathematica.

$\endgroup$
  • $\begingroup$ I looked at this once, and could not find a way. One can remove a cell from evaluation queue, and one can abort evaluation, but did not find "suspend" evaluation. This would be really hard to implement for the kernel I would think. $\endgroup$ – Nasser Jan 21 '17 at 11:34
  • $\begingroup$ The thing is, mathematica is able to pause it when the computer goes to sleep mode... So basically I would like to just send mathematica to sleep mode but not the rest of my system... $\endgroup$ – tonydo Jan 21 '17 at 11:35
  • $\begingroup$ When the computer is paused, everything running is paused by the OS itself. This is outside the control of any process really. But you are asking to pause just the Mathematica kernel process itself from the front end. I did not find a way. But may be there is. I do not know. $\endgroup$ – Nasser Jan 21 '17 at 11:39
  • $\begingroup$ What OS are you on? On Unix-like systems you can send SIGSTOP and SIGCONT signals to the corresponding Kernel process. On Windows you can halt/suspend processes from the resource monitor (search stack exchange for more details). Alternatively I'd suggest if you have long running code to organize it such that it saves intermediate state/results every once in a while and can start from such a snapshot. That will help in other situations as well and you can then just stop and resume the computation any time... $\endgroup$ – Albert Retey Jan 22 '17 at 19:51
  • $\begingroup$ See also (2874) $\endgroup$ – Mr.Wizard Feb 8 '17 at 8:45
7
$\begingroup$

Prior to version 10 of Mathematica, there was a menu option Evaluation / Interrupt Evaluation... with the hot-key ALT-, (comma). This would temporarily suspend the current evaluation in progress.

The bad news is that this menu item is gone. The good news is that the hot-key still works in versions 10 and 11.

The sequence of events is as follows:

  1. Start a long-running evaluation.
  2. At some point, press ALT-,
  3. A dialog appears that allows us to abort or continue -- or to "enter a subsession". This last will suspend the evaluation and return control to the front-end interface.
  4. We can evaluate expressions within the subsession as we see fit to examine the current kernel state.
  5. When we are ready to continue, we evaluate the expression Return (with no brackets).

This screenshot shows the process:

interrupting a long-running evaluation

Caution

I can only imagine that WRI has a reason for hiding the Interrupt Evaluation menu item. Perhaps the feature is being deprecated -- maybe there are issues trying to interrupt evaluations in recent versions due to increased parallelization. Before you start a great big evaluation, it might be prudent to experiment with this feature a few times with your actual code in order to see whether it will suspend properly.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.