23
$\begingroup$

So I'm in the middle of generating some plots and all of the sudden the frontend goes dead and I haven't saved my work. I'm using Mathematica 8 in MacOS X.

The MathKernel process is still running and I'm hoping to be able to extract the In/Out history from it through Terminal. Is there a way to do this?

$\endgroup$
2
  • 2
    $\begingroup$ I have coredumped the MathKernel and Mathematica processes in question and duly forced the crashing instances to close. I've re-done all my work, but if anyone knows an easy way to extract inputs from the dump (which is around 1.6GB of binary content) that'd be a great prevention against future crashes :) $\endgroup$ Commented Apr 8, 2012 at 16:48
  • $\begingroup$ While not directly a solution to your problem, you can instruct a notebook to automatically save as soon as an output is generated. That way if the notebook crashes, you'll at least not lose anything which was already output at that point (unless the notebook happens to crash during saving; in that case it might have the opposite effect; however it didn't happen to me yet, and you might reduce the risk by making copies (unfortunately Mathematica keeps the file open all the time [at least on Linux], which probably makes identifying the time when a save was completed hard). $\endgroup$
    – celtschk
    Commented Apr 14, 2012 at 19:47

3 Answers 3

7
$\begingroup$

If there is such a thing, I want to know it for windows and linux based OS'es also.

Battling with the same problem I have found 2 partial solutions:

  1. ctrl+s before hitting shift+enter (I think it's command+s for Mac's)
  2. if you ignored #1 then you might still be able to screenshot the code and reenter it

I have tried TextRecognize to restore the text from the image, but it's still a bit off.

enter image description here

Edit:

If your UI is not locked, you can

  • Quit the kernel, Evaluation -> quit kernel -> local (or add a shortcut for it)
  • Interrupt evaluation

    • on notebook interfaces: alt + , or Cmd + Option + .
    • on text-based interfaces: ctrl + C
$\endgroup$
1
  • $\begingroup$ Unfortunately, the notebook wasn't responding to my scrolling (or any other action for that matter) and the important bits of code were off-screen... $\endgroup$ Commented Apr 8, 2012 at 16:42
4
$\begingroup$

It just happened to me on the Mac and I managed to save it by doing the following. I opened the Activity Monitor (Applications->Utilities folder) and I found two wolfram kernels running in addition to the Mathematica itself. I killed the kernels by clicking on the "Force a process to quit" button (the little x-button on the upper-left corner). This unfroze mathematica so that I was able to save the file. I'm not sure how this works on Windows/Linux but probably one can do the same with the task manager.

$\endgroup$
1
  • $\begingroup$ +1 I can confirm that this works for me as well almost 5 years later under macOS 10.13 and Mathematica 11.2. $\endgroup$
    – Janosh
    Commented Nov 11, 2017 at 9:11
3
$\begingroup$

How about putting something like this into init.m

RunScheduledTask[If[FileExistsQ[
FileNameJoin[{$UserDocumentsDirectory, "recovermma.please"}]], 
    Save[FileNameJoin[{$UserDocumentsDirectory, "recovermma.txt"}],In]], 300]

It's pretty basic - the scheduled task just checks every five minutes for the existence of the trigger file and if it's there it saves the definition of In to a text file.

To "recover" the session you just create the trigger file in the appropiate folder and wait up to five minutes.

I am unable to crash the Front End at will so I don't know if it works under those circumstances.

$\endgroup$
5
  • $\begingroup$ Is there a particular reason why you only save In, not also Out? BTW, if you are on a Unix-like system (Linux, OS X), you can "crash" the front end from the shell with kill -9 $PID where $PID has to be replaced by the PID of the front end process (ps helps in finding that; if you have only one front end running, killall is an easier alternative). $\endgroup$
    – celtschk
    Commented Apr 14, 2012 at 22:42
  • $\begingroup$ No particular reason, you could save Out as well. It may even be possible to NotebookSave the entire active notebook, but I don't know if that works when the front end has crashed. There might also be a way to directly poll the front end for responsiveness instead of looking for a trigger file, but I'm not sure how to do that. I'm using Windows 7 and killing the front end process takes out the kernel process too. $\endgroup$ Commented Apr 15, 2012 at 11:47
  • $\begingroup$ You could use this memory leak to crash your front-end, and then let us know if it works. $\endgroup$
    – rcollyer
    Commented May 25, 2012 at 2:52
  • $\begingroup$ @rcollyer, I tried it but both the front end and kernel processes exited. They seem to be inextricably linked in Windows. $\endgroup$ Commented May 25, 2012 at 8:36
  • $\begingroup$ It was a thought. $\endgroup$
    – rcollyer
    Commented May 25, 2012 at 11:25

Your Answer

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

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