32
Short answer
The local variables of the form varname$... are used by the system, and it is unwise to use symbols with such names as local variables.
With, like many other lexical scoping constructs, performs excessive renamings, often even in cases where it isn't strictly necessary. This probably has to do with efficiency - full analysis may be more costly.
...
answered Jun 26 '16 at 13:47
Leonid Shifrin
108k1414 gold badges311311 silver badges401401 bronze badges
30
There are two processes running. The first process is the FrontEnd. The FrontEnd receives your keypresses and renders text and plots. The second process is the Kernel. The Kernel receives commands to perform calculations, stores the states of variables, and does pretty much all the calculating.
When you press Alt-., the FrontEnd immediately receives ...
29
You should consider using the sandbox functionality. You can create a subkernel and put it in sandbox mode this way:
link = LinkLaunch[First[$CommandLine]<> " -wstp -noicon"];
LinkWrite[link, Unevaluated@EvaluatePacket[Developer`StartProtectedMode[]]];
You can then interact with this subkernel using the standard LinkWrite and LinkRead functions. If ...
25
As people have figured out in the comments, this was a quite deliberate decision on our part. One which I can take a significant amount of credit/responsibility/blame for.
First a little bit about the extra kernel. The kernel is enabled using a password which causes it to run in Wolfram Player mode. It runs using the same binary as the regular kernel, ...
23
To access the errors, you need to invoke the Front End directly from the kernel. In effect, you end up telling the kernel to tell the FE to tell the kernel to do something, so that the FE can report any errors it finds. The method I use is
ClearAll[getFrontEndErrors];
SetAttributes[getFrontEndErrors, HoldAllComplete];
getFrontEndErrors[expr_] :=
Block[{...
20
You could launch a different kernel and use that to run the computation. You will be controlling this "slave kernel" from another Mathematica session. This will allow you to script even quitting and restarting the slave kernel.
Using parallel tools
This is simpler and I recommend trying this approach first.
Launch a single kernel:
kernel = ...
answered Nov 19 '16 at 19:26
Szabolcs
213k2222 gold badges532532 silver badges11181118 bronze badges
19
You need to daemonize your script:
nohup math -script test.txt 0<&- &>/dev/null &
Now this will run as a background process with no output captured. If your script does indeed produce output, just replace /dev/null with the filename.
In order to daemonize something you need to disconnect all the
automatically connected streams (stdin, ...
17
This can be relatively easily done using extremely useful $FrontEnd option "ClearEvaluationQueueOnKernelQuit" introduced by Chris Degnen.
Usage
Print @ $SessionID
quitAndEvaluate[
Print @ $SessionID
]
25183094379509806957
25183094575602627552
quitAndEvaluate[] will restart kernel without aby additional tasks. It may be useful if you want to ...
16
I have been solving exactly the same problem about 2 years ago (http://community.wolfram.com/groups/-/m/t/125587?p_p_auth=aZGMz5bs). Students are uploading piece of Mathematica (Wolfram Language) code which is run by a testing script (in Mathematica) and the results are compared with a reference solution.
To prevent the students to run potentially dangerous ...
16
One approach would be to run the evaluation in a second kernel which is controlled from a main kernel through MathLink/WSTP. Then your main kernel can detect if the MathLink connection dies.
You can implement this manually (a lot of work), or you can try to do it using the parallel computing tools, where much of the groundwork is already laid down.
In ...
answered Dec 17 '15 at 10:36
Szabolcs
213k2222 gold badges532532 silver badges11181118 bronze badges
16
Apparently, Throw is deactivated during kernel initialization. The following function can determine if Throw is inoperative:
throwInoperativeQ[] := CheckAll[Catch[Throw[False]], # /. Null -> True &]
The undocumented function CheckAll is used here because Check also appears to be unreliable when Throw is inoperative.
If we make the assumption that ...
16
The kernel crashes due to stack overflow. It is not safe to recurse too deeply. Increasing $RecursionLimit to values that are too great (and actually recursing that deep) risks a crash.
(So yes, in a way it's due to insufficient memory, but it has nothing to do with memoization. It is due to insufficient stack space.)
From the documentation:
On most ...
answered Nov 16 '17 at 11:12
Szabolcs
213k2222 gold badges532532 silver badges11181118 bronze badges
15
You can use GNU screen to make a sort of persistent terminal that allows you to resume work wherever you left off. Take a look at the many tutorials available.
It's not completely clear from your question whether the better solution is this, or nohup (see Stefan's answer).
Use nohup if your workflow is non-interactive: log in, start a batch job that ...
answered Feb 24 '14 at 17:54
Szabolcs
213k2222 gold badges532532 silver badges11181118 bronze badges
15
There is a setting in Mathematica that controls whether it can access the internet. Go to Preferences -> Internet Connectivity and uncheck "Allow the Wolfram System to access the Internet". Disabling this will disable some features that depend on internet access, such as Wolfram|Alpha queries.
This setting can also be controlled by the $AllowInternet ...
14
You cannot Quit kernel while evaluation is still running: the Quit[] command will be placed in the queue and executed only after finishing of evaluation of all the previous inputs. In contrast, Evaluation â–º Quit Kernel will quit the kernel immediately even if it is still running.
UPDATE
As Kuba noticed in the comments, via "Preemptive" link it is ...
answered Dec 2 '14 at 6:39
Alexey Popkov
50.2k44 gold badges128128 silver badges313313 bronze badges
14
After some spelunking, I found a file which contains a lot of initialization code, including reading the kernel init.m file, loading Autoload packages, loading anything set with the -initfile option, starting the paclet manager (which may autoload packages), and many other things. It is
SystemFiles/Kernel/SystemResources/$SystemID/sysinit.m
Towards the ...
answered Nov 27 '16 at 19:11
Szabolcs
213k2222 gold badges532532 silver badges11181118 bronze badges
14
This bug has been fixed by a paclet update.
This would be applied automatically whenever the functionality is used in a new kernel (as long as the paclet manager has updated its local site index, which typically happens once per session).
To force an immediate installation, evaluate
PacletSiteUpdate /@ PacletSites[];
PacletInstall["FFmpegTools"]
which ...
13
This message is issued by Function itself. To see this, try
Function[Module[{slot = 1}, Slot[slot]]]
If Function has named formal parameters, the message goes away:
Function[x, Module[{slot = 1}, Slot[slot]]]
So to fix this first we need to find out where is the argument passed to ParallelEvaluate wrapped by Function. Fortunately the parallel tools are ...
answered Jan 13 '13 at 20:02
Szabolcs
213k2222 gold badges532532 silver badges11181118 bronze badges
13
Updated
This happens because your DynamicModule returns a dynamic object of which x is passed on to the front-end before the scheduled task starts, so the front-end-x cannot be modified anymore by any process (more details at the end).
The problem can be further simplified. This works:
RemoveScheduledTask@ScheduledTasks[];
DynamicModule[{x = 0}, ...
answered Dec 5 '13 at 15:03
István Zachar
44.1k1919 gold badges128128 silver badges271271 bronze badges
13
Assuming FrontEnd survives, prepare 3 cells:
(*init cell, won't be needed later*)
state = CurrentValue[EvaluationNotebook[], {"TaggingRules", "state"}] = 0;
SetOptions[ #,
{CellTags -> {"Procedure"}, ShowCellTags -> True}
]& /@ {NextCell[], NextCell @ NextCell[]};
CurrentValue[$FrontEndSession, "...
13
Update
Leaving my original answer below for historical purposes, however it only applies up until version 11.1.1.
As of version 11.2.0, the kernel startup initialization has been overhauled and this example (as well as others) now works correctly: placing the URLFetch call in init.m does result in an output like
<!doctype html>
<html lang="en" ...
13
It's a type of otherwise harmless bug that tends to come and go with versions. I would suggest to report it to Wolfram, but also not to worry about it. Notice that the symbols have no associated definitions, which means that they will not interfere with your code.
A potential way in which such a situation can arise is the following. Imagine you put
Sqr[x_] ...
12
Not a full answer, but a little too long for a comment.
You may need to pay a close attention to licensing. If the results of your computation are used on a single machine (e.g. somehow saved to a database or used further in the computation), you may only need a professional single-machine license. If they are going to be used by other employees / machines ...
answered Jan 11 '13 at 20:51
Leonid Shifrin
108k1414 gold badges311311 silver badges401401 bronze badges
12
Now that the workaround has worked for me for days without crash, let me put it as an answer myself. The crash (at least in my case) is because of the kernel tries to connect to internet and something wrong happened there. To solve the problem, uncheck
Preference -> Internet Conectivity -> Allow the Wolfram System to access the Internet
12
Here's an approach to fix the code behind Terminal` - Execute the following code to restore the functionality of the package:
<< Terminal`
ExportString["", "TTY"];
DownValues@System`Convert`BitmapDump`ExportTTY = DownValues@System`Convert`BitmapDump`ExportTTY /.
{
TextStyle -> LabelStyle,
HoldPattern[pre : (data_ = _[___, gr_, "...
11
You can use FileNameJoin to assemble file names in a robust and platform-independent way. This will solve the difficulties with the trailing /.
You can also use AbsoluteFileName to bring a path to canonical form. This works only with paths that exist.
For example, to compare Directory[] and NotebookDirectory[], you can use
AbsoluteFileName@Directory[] ===...
11
The crash may be avoided by turning off the Suggestions Bar.
The reason is that one of the computations attempted by the predictive interface in the background, namely
Solve[(0.000092742725 - 0.000015933052*I)*
E^((0. + 3.1934271000000003*^-10*I)*t) - (0.0000981431 +
0.0001437239*I)*
E^((0. + 1.4229429000000001*^-9*I)*t) + (0.0057300369 -
...
10
I would not classify this as a bug. The behaviour of a Slot expression that is not directly contained within a Function expression is not defined by the documentation, and is unreliable in practice. Consider the following two functions:
f[x_] := x + 100
g[x_] := x + # &[100]
They appear to be essentially equivalent, but it just so happens that the ...
10
webMathematica is probably the most secure solution. Unless someone hacks your sever there is no way to get to the source of your program.
Using webMathematica you could easily use standard Web services. Check out the documentation
So e.g., you can create a macro in Excel and then it looks like
In this way you use standard web technology and keep all your ...
10
Could use $Pre to wrap things in MemoryConstrained. I'll illustrate with an unusually tight constraint.
SetAttributes[memcon, HoldAll]
memcon[new_] := MemoryConstrained[new, 10^4]
$Pre = memcon;
Examples:
ByteCount[Range[10^6]]
(* Out[4]= $Aborted *)
s = N[SparseArray[Table[{2^i, 4} -> i, {i, 20}]]]
(* Out[5]= $Aborted *)
answered Jan 13 '13 at 20:56
Daniel Lichtblau
52.4k22 gold badges8989 silver badges182182 bronze badges
Only top voted, non community-wiki answers of a minimum length are eligible
Related Tags
kernel × 302parallelization × 50
kernel-startup × 37
front-end × 36
crash × 32
evaluation × 28
remote-access × 28
bugs × 20
notebooks × 17
scripting × 13
memory × 12
packages × 10
mathlink-or-wstp × 10
linux × 10
system × 10
command-line × 9
warning-messages × 8
plotting × 7
functions × 7
export × 7
dynamic × 7
windows × 7
programming × 6
differential-equations × 5
performance-tuning × 5