I have a complicated script (not just written by me) that gets called using MathKernel -script script.m
. Among others script.m
uses parallel subkernels and external calls through RunProcess
and OpenRead["!"<>cmd]
. I sometimes encounter a situation where all lines until Quit
get run yet the task never completes. So something of the form
lotsOfCode
...
Print["We arrived at Quit"];
Quit[]
Here "We arrived at Quit"
will print but the task will never Quit
. lotsOfCode
should be viewed as a black box. What could be preventing the script from terminating? How can I really Quit?
System: Linux, Mathematica 11.1 (and 12.1)
I am happy with a linux based solution so I'm thinking I should probably invoke something like kill
through something like RunProcess
in order to get Mathematica to kill itself. A cleaner Mathematica based solution that figures out what is preventing it from quiting would of course be nicer.
This question seems related though it is looking for a different type of solution.
Quit
should never be necessary in a script. $\endgroup$Quit
out gives the same hanging result.Quit
is there to emphasize that the very last line just before it got reached and yet the script did not terminate. $\endgroup$Quit
present but are you saying thatQuit
would not work? (As in act asAbort[]
to finish the computation so that the script terminates.) $\endgroup$