6
$\begingroup$

This question shows how to print output to the console, but how about messages?

For the main kernel, I know this way:

SetOptions[$FrontEnd, MessageOptions -> {"KernelMessageAction" -> "PrintToConsole"}]

But if used in Parallelize, I am returned

SetOptions::optnf : MessageOptions is not a known option for Null.

$\endgroup$

1 Answer 1

5
$\begingroup$

Assuming that "console" means the Messages notebook window (and not, say, stdout when run in a terminal session), try something like the following

SetOptions[$FrontEnd, MessageOptions -> {"KernelMessageAction" -> "PrintToConsole"}]

$KernelCount; (* load the Parallel` code *)

Unprotect[MessagePacket]; (* patch MessagePacket upvalue *)

MessagePacket /: 
 Parallel`Protected`PacketHandler[
  t : MessagePacket[sym_, tag_, text_], Parallel`Kernels`kernel_] := 
 NotebookWrite[MessagesNotebook[], 
  Cell[text, "Message", "MSG", 
   CellLabel -> Parallel`Kernels`Private`kernelString[Parallel`Kernels`kernel], 
   ShowCellLabel -> True]]

ParallelEvaluate[1/0]

(* {ComplexInfinity, ComplexInfinity, ComplexInfinity, ComplexInfinity} *)

enter image description here

$\endgroup$

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.