is an option that specifies functions to apply when events are generated.
HandlerFunctions
is an option that specifies functions to apply when events are generated.
Details
- The typical setting for HandlerFunctions is "event1"->f1,"event2"->f2,…, which specifies that when eventi is generated, the function fi should be applied to an association whose elements are specified by HandlerFunctionsKeys.
- The events that can be generated by particular tasks are listed under the functions that submit the tasks.
- In the HandlerFunctions association, the special element "UnhandledEvent"->f uses the function f for any event for which no explicit handler was specified.
Examples
Basic Examples (8)
Display the result of evaluation after the task is finished:
SessionSubmit[Integrate[Log[t] ^ 4 / Sqrt[1 - t ^ 2], {t, 0, 1}], HandlerFunctions -> <|"TaskFinished" :> MessageDialog|>, HandlerFunctionsKeys -> {"EvaluationResult"}]Print the complete Association available to a handler function:
SessionSubmit[N[Pi, 200], HandlerFunctions -> <|"TaskFinished" -> Print|>, HandlerFunctionsKeys -> All]Display the result of Print evaluated in a subkernel:
LocalSubmit[Print["Hello!"],
HandlerFunctions -> <|"PrintOutputGenerated" -> (Print[#PrintOutput]&)|>,
HandlerFunctionsKeys -> {"EvaluationExpression", "PrintOutput"}]Display a dialog when a message is generated:
SessionSubmit[1 / 0, HandlerFunctions -> <|"MessageGenerated" -> MessageDialog|>,
HandlerFunctionsKeys -> {"EvaluationExpression", "MessageOutput"}]Print messages generated by the subkernel:
LocalSubmit[1 / 0, HandlerFunctions -> <|"MessageGenerated" -> (Message[#MessageOutput]&)|>, HandlerFunctionsKeys -> {"MessageOutput"}]Handle the "BodyReceived" event when it is generated by URLSubmit:
URLSubmit["http://www.wolfram.com", HandlerFunctions -> <|"BodyReceived" -> Print|>]Store the headers with a variable when they are received:
URLSubmit["http://www.wolfram.com", HandlerFunctions -> <|"HeadersReceived" -> ((headers = #Headers)&)|>]headersPrint the status code and content type when the task is finished:
URLSubmit["http://www.wolfram.com", HandlerFunctions -> <|"TaskFinished" -> Print|>, HandlerFunctionsKeys -> {"StatusCode", "ContentType"}]Related Guides
History
Text
Wolfram Research (2016), HandlerFunctions, Wolfram Language function, https://reference.wolfram.com/language/ref/HandlerFunctions.html.
CMS
Wolfram Language. 2016. "HandlerFunctions." Wolfram Language & System Documentation Center. Wolfram Research. https://reference.wolfram.com/language/ref/HandlerFunctions.html.
APA
Wolfram Language. (2016). HandlerFunctions. Wolfram Language & System Documentation Center. Retrieved from https://reference.wolfram.com/language/ref/HandlerFunctions.html
BibTeX
@misc{reference.wolfram_2026_handlerfunctions, author="Wolfram Research", title="{HandlerFunctions}", year="2016", howpublished="\url{https://reference.wolfram.com/language/ref/HandlerFunctions.html}", note=[Accessed: 13-June-2026]}
BibLaTeX
@online{reference.wolfram_2026_handlerfunctions, organization={Wolfram Research}, title={HandlerFunctions}, year={2016}, url={https://reference.wolfram.com/language/ref/HandlerFunctions.html}, note=[Accessed: 13-June-2026]}