0

My problem is that the second notebook file opens but waits for the first notebook to be evaluated. I want to execute both file1.nb and file2.nb at the same time. Here is my code. any idea?

NotebookPauseForEvaluation[nb_] := Module[{},
    While[NotebookEvaluatingQ[nb], Pause[1]]
];

NotebookEvaluatingQ[nb_] := Module[{}, SelectionMove[nb, All, Notebook]; Or @@ Map["Evaluating" /. # &, Developer`CellInformation[nb]] ];

UsingFrontEnd[ nb1 = NotebookOpen["./file1.nb"]; SetOptions[nb1, Evaluator -> "RemoteKernel1"]; SelectionMove[nb1, All, Notebook]; SelectionEvaluate[nb1]; NotebookPauseForEvaluation[nb1]; NotebookSave[nb1];

nb2 = NotebookOpen["./file2.nb"];
SetOptions[nb2, Evaluator -> "RemoteKernel2"];
SelectionMove[nb2, All, Notebook];
SelectionEvaluate[nb2];
NotebookPauseForEvaluation[nb2];
NotebookSave[nb2];

];

  • Before executing the notebooks, assign different kernels to the two notebooks, using the menu option Evaluation > Notebook's Kernel. Note, however, that your license may limit the number of kernels running simultaneously. – bbgodfrey Nov 13 '21 at 17:47
  • thanks for comment. i did it before. – Mohammad Shahbazi Nov 13 '21 at 17:49
  • Another thing you usually should do is assure that the default Contexts for the two notebooks are different, so that they do not interfere with each other. I usually use Evaluation > Notebook's Default Context > Unique to This Notebook. – bbgodfrey Nov 13 '21 at 17:54
  • Since this code runs in a hpc cluster, i don't have access to compute nodes to do this, how can i do this programmatic? – Mohammad Shahbazi Nov 13 '21 at 18:07
  • Good question for which I do not have an answer. If you can get to the Options Inspector you can set many useful defaults, including Unique to This Notebook. – bbgodfrey Nov 13 '21 at 18:14
  • For reference: https://support.wolfram.com/12425?src=mathematica – Syed Nov 13 '21 at 20:18
  • https://mathematica.stackexchange.com/questions/43900/new-kernel-for-notebook – Syed Nov 13 '21 at 20:20

0 Answers0