18
$\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$
5
  • $\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, 2017 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$
    – dan-ros
    Jan 21, 2017 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, 2017 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$ Jan 22, 2017 at 19:51
  • $\begingroup$ See also (2874) $\endgroup$
    – Mr.Wizard
    Feb 8, 2017 at 8:45

1 Answer 1

15
$\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$
4
  • 2
    $\begingroup$ FYI: This is still on their website and it's not listed as depricated, so it doesn't seem to be that discouraged. Thanks for the tip. reference.wolfram.com/language/tutorial/… $\endgroup$ Feb 28, 2020 at 22:30
  • 3
    $\begingroup$ I checked it with Mathematica 12.0. it also works. $\endgroup$ Jul 16, 2020 at 4:28
  • $\begingroup$ Wow! I had no idea Return had this functionality. I do wonder if this places unnecessary code into Return that must be checked with every evaluation? $\endgroup$
    – Sam Blake
    Aug 31 at 21:24
  • 1
    $\begingroup$ @SamBlake I suspect not, because it uses the inert symbol Return rather than the expression Return[] which would invoke its definitions. My guess is that the subsession UI itself has built-in logic that triggers on the symbol Return. $\endgroup$
    – WReach
    Aug 31 at 21:41

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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