6

I have a well-honed Control-S reflex (i.e. I obsessively save my work), but when Mathematica crashes with a file open the saved changes are not recovered when I restart Mathematica and open the file. It reverts back to the file's state when I first opened it before making (and saving) any changes.

How can I actually save my work, without needing to save, close and re-open a notebook with the same obsessive regularity that I "save"?

I'm running Mathematica 8.0 on a Windows XP x64 machine.

Edit: Just to clarify, I'm not so worried about the crashing. I'm concerned about saving not actually saving.

Eli Lansey
  • 1,130
  • 2
  • 15
  • 28
  • If you quit Mathematica normally, are your changes successfully saved? – Brett Champion Dec 13 '11 at 15:28
  • Yes, if I close the file (and/or Mathematica) normally then the changes are saved – Eli Lansey Dec 13 '11 at 15:31
  • Can you evaluate `Options[EvaluationNotebook[]]` from within the notebook and post the result? Or post the notebook somewhere? – Brett Champion Dec 13 '11 at 15:39
  • @BrettChampion {FrontEndVersion -> "8.0 for Microsoft Windows (64-bit) (November 7, 2010)", StyleDefinitions -> "Default.nb", WindowMargins -> {{Automatic, 42}, {39, Automatic}}, WindowSize -> {1370, 794}} – Eli Lansey Dec 13 '11 at 15:43
  • Well those options are nice and boring. :-) Is the notebook especially large, or live in some 'special' location on your hard drive? – Brett Champion Dec 13 '11 at 15:47
  • So, you save the file and what causes the crash? –  Dec 13 '11 at 15:49
  • And you do not have the notebook open in another M- session? –  Dec 13 '11 at 15:50
  • Not particularly. It's not filled with crazy things, either. It's a fairly boring notebook. I'm less concerned about the crashing than I am about the lack of saving. – Eli Lansey Dec 13 '11 at 15:50
  • @ruebenko The crash can be caused by any number of different reasons (opening a different, corrupt notebook; graphics overload; dog ate my RAM; etc). I'm not so worried about that. My concern is that my file is not actually saved when I think it is. – Eli Lansey Dec 13 '11 at 15:53
  • @Eli I am trying to figure out if the crash prevents M- from saving the file properly. But it seems there is a fair amount of time between the save and the crash. –  Dec 13 '11 at 15:58
  • @ruebenko Plenty of time. I can be working on a file all day, saving all the time. Then the front end crashes and I lose the work saved many times over the course of many hours. – Eli Lansey Dec 13 '11 at 16:00
  • May be you can try to restore M to its original factory shipped state and see if this problem remain? Sometimes this for me solved some strange problem (but not as strange as yours). Before starting M, hold the SHIFT and CONTROL key down, keep holding them down while starting M until the M flash screen comes up. Now release the keys. This will reset M init files. something to try... – Nasser Dec 13 '11 at 23:45
  • This just happened to me with Mathmematica 12 on Windows 10. Two days of work lost, despite frequent saving! Infuriating. – David Feb 15 '21 at 07:50

4 Answers4

2

This may be a case of Windows not flushing its disk cache to disk. You might want to try the Sysinternals' tool Sync. "Use it whenever you want to know that modified file data is safely stored on your hard drives."

You can have Mathematica call Sync using Run and automate the process in the background using scheduled tasks like in this answer.

Community
  • 1
  • 1
Sjoerd C. de Vries
  • 16,122
  • 3
  • 42
  • 94
1

I have a similar problem with Mathematica 10, my temporary solution is to save to a filename with a name ending with "a" - "filenamea.nb", and switch and save to a name ending with b "filenameb.nb".

I've been using Dropbox to restore older version until I discovered that in this version Mathematica doesn't flush the files (at all it seems unless you close the file). This is especially a problem when it crashes.

It is possible that some of this could be tweaked in the advanced options, but I couldn't figure out how yet, I posted a question with Wolfram. To be continued...

qpd
  • 11
  • 1
  • Your message is from 7 years ago, but did you get an answer from Wolfram? I just had the same issue with Wolfram 12 on Windows 10. – David Feb 15 '21 at 07:51
1

The command NotebookSave[] can rescue you at times.

It has happened to me that I think I am saving with ctrl-S but then I discover that actually nothing is being saved. The star (asterisk) next to the filename in the title bar does not disappear (giving the most obvious hint that something is wrong if you actually look) and checking the timestamp in the notebook's folder shows that the file has not been changed.

Trying Save (or Save As...) from the file menu also does nothing when this problem has arisen. And other opened notebooks cannot be saved either in this state. When this has happened to me, it has been possible to use Save Selection from the file menu to at least have a copy in other forms (like PDF), but while this might at least make a record of the commands, it is tedious to find and type in the changes since the last successful save (after you give up and force Mathematica to close).

It just happened to me again (for the third time ever). And I discovered that the command NotebookSave[] saves the file -- just execute it as a command in the very file that you have been trying to save. (Check the documentation for other options; I didn't try the other forms of the command.) In my case it just saved everything, the "star" disappeared, the timestamp updated, and all was well. Not only that, but other files could now also be saved in the usual ways; the system seemed cured. (But I took the opportunity to restart the program in case some cooties were still lurking.)

Why it happened is a mystery, but I was over 3000 commands deep in this particular session (probably about a week long), with about two dozen other notebooks loaded and some in various states of being edited. And I noticed that my open folders had all vanished from the File Explorer list. And the Directory[] command in Mathematica gave a different directory than earlier, reverting to a default user directory. So either Mathematica (version 13) or the operating system (Windows 11) was feeling poorly.

Oh, and as is typical for me, I had just recently managed to execute some buggy commands that spit out reams of warnings about recursion overflows and such, the usual careless thing. Often when that happens, the kernel crashes. In this case it did not, so I merrily proceeded as if everything was okay. Maybe it was not.

Rick Mabry
  • 11
  • 1
1

Edit->Preferences->Advanced; Open Option Inspector.

Lookup: NotebookAutosave

This will save every time you press shift+enter. It can be a disk burden for large files.

  • Again, I do _save_ the files, it's just that with a crash the saves don't stick. Were I to close and re-open the file, the saves stick. – Eli Lansey Dec 13 '11 at 15:36
  • So the star in the file name did vanish? Sometimes you press Ctrl+S and think the notebook was saved but it was not. –  Dec 13 '11 at 15:40
  • The best solution to this problem is not to type anything that will cause Mathematica to crash :) – Nasser Dec 13 '11 at 22:51
  • 3
    @NasserM.Abbasi: A strange game. The only winning move is not to play. Care to play a nice game of chess? – Mike Bailey Dec 14 '11 at 00:28