3

I have a notebook Main.nb. This notebook contains a While[...] loop that takes about twelve hours to run. I have a second notebook called DataPreparation.nb. As the name suggests, the contents of DataPreparation.nb should be evaluated before the While[...] loop mentioned above.

Scenario 1 (with no bug):

  1. From DataPreparation.nb notebook, Select All and Evaluate.
  2. Switch to Main.nb notebook and start evaluation of While[] loop.
  3. If I need to abort the twelve hour While[] loop, I use Alt+. and it promptly stops. Good.

Scenario 2 (with the bug)

  1. From Main.nb, I invoke this command:NotebookEvaluate["DataPreparation.nb", InsertResults -> False].
  2. Start evaluation of While[] loop.
  3. If I need to abort the twelve hour While[] loop, I use Alt+. The abort command is ignored.
  4. To abort the twelve hour process, I must quit Kernel. I lose my work.

It appears that after I have used NotebookEvaluate, Mathematica loses track of where the abort command should be directed. I know that is an imprecise description of the problem, but it is the best I can do.

ps. This question is different from the question here. The difference is that in the earlier question, the loop which can not be aborted is contained in EvaluateNotebook[...]. In my case, I am simply calling EvaluateNotebook[...] . The while loop which can't be aborted is contained in the main notebook.

MarcoB
  • 67,153
  • 18
  • 91
  • 189
Chris
  • 447
  • 2
  • 12
  • Strange. Something as simple as t = 0;While[t < 100000000, t++] in notebook T can easily be aborted. But if you create two different notebooks A and B, where A contains only something like x=7+2 and B calls NotebookEvaluate on A, then the While operation in notebook T cannot be aborted. – Jean-Pierre Feb 19 '21 at 20:22
  • Thanks @Jean for confirming my observation. It is easy to avoid using NotebookEvaluate. I was just wondering if someone can explain what is going on. – Chris Feb 19 '21 at 20:48
  • I think you are misunderstanding the other question you linked. It is indeed the same issue. In that question, the Do loop which can't be aborted is in the same notebook from which the NotebookEvaluate was called, just like here. – Jason B. Feb 19 '21 at 21:51
  • @Jason. I guess you are right. I did misinterpret that other question. If you think I must, I will delete this question. – Chris Feb 19 '21 at 21:54
  • Leave it open so future searchers can find it, but you can close it as a duplicate. Can you check if the workaround I posted there works for you? – Jason B. Feb 19 '21 at 21:55
  • @Jason I will try that workaround later today and post results here. I'm expecting it will work, but I have no experience with "FrontEndExecute" or "FrontEndToken". Still, it should be easy to cut and paste when I get back to my computer. – Chris Feb 19 '21 at 21:58
  • Not that workaround, which basically avoids calling NotebookEvaluate. The one I just posted, which just means calling MathLink`LinkAddInterruptMessageHandler[$ParentLink] directly after calling NotebookEvaluate. – Jason B. Feb 19 '21 at 22:01
  • @Jason RE: MathLink`LinkAddInterruptMessageHandler[$ParentLink] Yes, that workaround seems to work. Thanks. Maybe you can figure out what is happening and post a full answer here. – Chris Feb 19 '21 at 22:07
  • @Jason Yes this restores the aborts, but it is not related to NotebookEvaluate being in the same or a different notebook, as indicated in the example I provided earlier. Opening a new notebook to enter the MathLink line restores the abort in my notebook T. – Jean-Pierre Feb 19 '21 at 22:10
  • Does this rise to the level of a bug? – Chris Feb 19 '21 at 22:13
  • @Chris - this is a bug for sure, it's also a duplicate of the other question. – Jason B. Feb 19 '21 at 22:23
  • @MarcoB Please see discussion in comments. – Chris Feb 19 '21 at 23:29

0 Answers0