Skip to main content
added 1 characters in body
Source Link
F'x
  • 10.9k
  • 3
  • 52
  • 92

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.

If you control the launch of the main evaluation process, then a very simple way is to wrap your code in a dynamic enviroment (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.

If you control the launch of the main evaluation process, then a very simple way is to wrap your code in a dynamic environment (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.

Source Link
Leonid Shifrin
  • 114.9k
  • 16
  • 333
  • 424

If you control the launch of the main evaluation process, then a very simple way is to wrap your code in a dynamic enviroment (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.