When using a function that includes Print statements, one can suppress the output by

Print; Unprotect[Print]; Print = Null &

This doesn't work when the function is evaluated in


Is there a way to do that? Thank you!

  • 1
    $\begingroup$ Have you tried executing the redefinition of Print in all the kernels you are using for evaluation ? $\endgroup$ Commented May 2, 2012 at 10:37

3 Answers 3


You can use dynamic scoping, i.e. the Block construct, to temporarily "forget" or redefine Print.

Print; Unprotect[Print]; Print = Null &

This works with ParallelTable for me.

  • $\begingroup$ works! thank you. $\endgroup$
    – user13655
    Commented May 2, 2012 at 10:47
  • 3
    $\begingroup$ I would find it unusual if this worked, because the definition of Print is not synchronized across kernels, and indeed it does not work here. I tried Block[{}, Print; Unprotect[Print]; Print = Null &; ParallelDo[Print[i], {i, 1, 10}]] which is completely analogous with your example, yet it does print the output. Furthermore, in your example the modification of Print is not temporary. $\endgroup$
    – Szabolcs
    Commented May 2, 2012 at 11:30
  • 1
    $\begingroup$ @noe Try in a fresh kernel. If you use the exact same code that you posted, the modification cannot be temporary, because you didn't pass Print to Block in the first argument. Then there's the question of synchronization between subkernels. $\endgroup$
    – Szabolcs
    Commented May 2, 2012 at 11:47
  • 1
    $\begingroup$ The only way I can see this working is if you put this code inside ParallelTable, but even then you will change the definition of Print permanently for the parallel kernels. Try for example running ParallelDo[Print[i], {i,10}] afterwards. A safer option would be to do something like ParallelTable[Block[{Print}, Print = Null &;...], ...]. $\endgroup$
    – Heike
    Commented May 2, 2012 at 12:31
  • 1
    $\begingroup$ @noe If you put the Block inside ParallelTable then in fact Block had no effect. Dynamic scoping was not used. What happens is that Print is redefined permanently in all the subkernels, but not in the main kernel. $\endgroup$
    – Szabolcs
    Commented May 2, 2012 at 13:20


ParallelDo[Block[{Print = Null&}, Print[{i, $KernelID}]], {i,1,10}]

You can also make it into a function:

SetAttributes[ParallelDoSilent, HoldAll]
ParallelDoSilent[expr_, iter_] :=
  ParallelDo[Block[{Print = Null&}, expr], iter]

ParallelDoSilent[Print[{i, $KernelID}], {i,1,10}]
  • 2
    $\begingroup$ +1, yes, this is the correct and general solution. This is good reading on Block (for the OP): stackoverflow.com/questions/6661393/… With is not going to act inside functions, and permanently redefining Print is error-prone and inconvenient. $\endgroup$
    – Szabolcs
    Commented May 2, 2012 at 13:31
  • $\begingroup$ @Szabolcs Thanks for pointing out some of the subtle properties of Block $\endgroup$ Commented May 3, 2012 at 12:56
  • $\begingroup$ How do I revert this? If I want to have Print work again as usual in the current Mathematica session? $\endgroup$
    – a06e
    Commented Feb 1, 2016 at 15:47
  • $\begingroup$ @becko: As soon as the Block finishes execution, Print is automatically reverted to the previous value (which should be the original Print function, unless you did any further change to it outside the Block). If you want to re-enable Print while still inside the Block, just use Print =. to undo the assignment. $\endgroup$
    – celtschk
    Commented Jun 10, 2016 at 17:16

This seemed to work for me.

ParallelEvaluate[Print = Null &];
ParallelDo[Print[{i, $KernelID}], {i, 1, 10}]

This also seemed to work:

ParallelDo[With[{Print = Null &}, Print[{i, $KernelID}]], {i, 1, 10}]

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.