2
$\begingroup$

File/New/Notebook creates a new notebook using the same current kernel. Is it possible to make it create a new kernel by default? I know how to create a new kernel manually and set that kernel to my notebook. What I'm asking is how to automate that process so that File/New/Notebook automatically creates a new kernel and uses it.

$\endgroup$
2
  • 1
    $\begingroup$ How many kernels would you like this to go up to? It's pretty expensive in terms of processors to be making a new kernel for every notebook. On the other hand if you really want this see Kuba's comments here: mathematica.stackexchange.com/questions/43900/… $\endgroup$
    – b3m2a1
    Commented Jun 10, 2018 at 2:14
  • 1
    $\begingroup$ Also, if you have a normal license, you cannot create arbitrary many new kernels. Usually, the limit is 2 main kernels. If you happen to be in a network with infinitely many licenses, however, this won't be an issue. $\endgroup$
    – halirutan
    Commented Jun 10, 2018 at 2:57

1 Answer 1

2
$\begingroup$

Summing up, I don't think you can get away in a long run with what you want. But maybe you can, I will give you few ideas to experiment with, there is no the best way as your request is not standard.


Maybe it would be enough to to set separate CellContext -> Notebook for those notebooks?

Based on Create new notebook at fixed size, it can be done as follows:

SetOptions[$FrontEnd, NotebookEventActions :> {
  {"MenuCommand", "New"} :> CreateNotebook["Default", CellContext -> Notebook]}
]

In case you really want separate kernels, you can create them dynamically: How to set up LinkSnooper for monitoring FrontEnd--Kernel communication?

CurrentValue[$FrontEnd, {EvaluatorNames, "newUniqueName"}] = {
  "AutoStartOnLaunch" -> False
};

and then

NotebookEventActions :> {
  {"MenuCommand", "New"} :> CreateNotebook["Default", Evaluator -> "newUniqueName"]
}

Considering how many new notebooks one may create it is probably good idea to clean/delete the kernel on MenuCommand/WindowClose or something. But then you you to recreate it when the notebook is opened. You could you NotebookEventActions :> Refresh[reinitcode, None] for that.

Let me know if there is anything I did not cover.

$\endgroup$

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.