Let us start with a variant of an example in the documentation of AbortKernels
.
We launch four subkernels:
LaunchKernels[4];
We create four simple evaluation objects. Each of them is an infinite loop, increasing a common shared variable after a random time. While showing the value of the shared variable, we parallel evaluate the tasks until we manually abort the evaluation.
found=0.;
SetSharedVariable[found];
tasks=Table[ParallelSubmit[While[True, Pause[RandomReal[]];found=found+1]], {4}]
PrintTemporary[Dynamic[found]];
CheckAbort[WaitAll[tasks], AbortKernels[]];
found
Run the above command and abort manually a number of times. Ultimately, Mathematica will hang. When this happens is highly inpredictable. In my tests, it varied from 1 (immediate hanging) to 8 (7 succesfull abortions).
The problem also turns up when we use CloseKernels
instead of AbortKernels
. Run and abort the next command a number of times.
LaunchKernels[4];
Dynamic[Kernels[], UpdateInterval->1]
found=0.;
SetSharedVariable[found];
tasks=Table[ParallelSubmit[While[True, Pause[RandomReal[]];found=found+1]], {4}]
PrintTemporary[Dynamic[found]];
CheckAbort[WaitAll[tasks], CloseKernels[]];
found
When Mathematica hangs after abortion, it seems theat the subkernels are not closed.
It has nothing to with evaluation objects, as is shown in the next command:
LaunchKernels[4];
found=0.;
SetSharedVariable[found];
PrintTemporary[Dynamic[found]];
CheckAbort[ParallelDo[Pause[RandomReal[]];found=found+1, {10000}], CloseKernels[]];
found
WRI CASE:4041721, 2018-04-16.