If you control the launch of the main evaluation process, then a very simple way is to wrap your code in a dynamic enviromentenvironment (Block
), which would set some flag:
mainEvaluationOngoingQ[] := TrueQ@mainEvaluationQ
Block[{mainEvaluationQ = True}, Do[i^2, {i, 1, 10^8}]]
You can automate this by creating an environment:
SetAttributes[withMainEvaluation, HoldAll];
withMainEvaluation[code_] :=
Block[{mainEvaluationQ = True}, code]
You can further automate this with $Pre
, if needed: $Pre = withMainEvaluation
.