SessionSubmit

SessionSubmit[expr]

submits an asynchronous task to evaluate expr in the current session.

SessionSubmit[ScheduledTask[expr,spec]]

submits a task to evaluate expr in the current session on the schedule defined by spec.

Details and Options

  • SessionSubmit[] returns TaskObject[] to represent the task it creates.
  • Possible values of spec are those supported by the ScheduledTask.
  • The following options can be given:
  • HandlerFunctions<||>how to handle generated events
    HandlerFunctionsKeysAutomaticparameters to supply to handler functions
    MethodAutomatichow to determine when to allow the task to run
  • Possible settings for the Method option include:
  • "Idle"run only when the session is waiting for user input
    Automaticrun at any time, including during computations
  • During the execution of the task, the following events can be generated:
  • "TaskStarted"task is started
    "ScheduleTriggered"scheduled task evaluation is beginning
    "MessageGenerated"evaluation generated a message
    "PrintOutputGenerated"evaluation generated print output
    "ResultReceived"evaluation generated a result
    "ScheduleExecuted"scheduled task evaluation is executed
    "TaskStatusChanged"task status changed
    "TaskFinished"task is completely finished
    "TaskRemoved"task is being removed
  • With the specification HandlerFunctions-><|,"eventi"->fi,|>, fi[assoc] is evaluated whenever eventi is generated. The elements of assoc have keys specified by the setting for HandlerFunctionsKeys.
  • Possible keys specified by HandlerFunctionsKeys include:
  • "EvaluationExpression"expression being evaluated
    "EvaluationResult"result of the evaluation
    "MessageOutput"content of message generated
    "PrintOutput"content of print output generated
    "Task"the object representing the task
    "TaskStatus"the status of the task
    "TaskType"type of the task
    "TaskUUID"unique task identifier
    "EventName"the name of the event being handled
  • The expression to evaluate is returned wrapped in Hold.
  • For scheduled tasks, the following additional keys can be specified:
  • "Schedule"task schedule specification
    "RunInterval"interval between task runs
    "PreviousRunCount"number of times the task has already run
    "RemainingRunCount"number of times the task still has to run
    "TotalRunCount"total number of times the task is scheduled to run
    "NextScheduledTime"next time the task is scheduled to run
  • The task submitted by SessionSubmit is run in the current Wolfram Language session and has access to all variables and other states of that session.
  • The task is run preemptively, both when the system is waiting for input and during other evaluations.
  • If expr is not a ScheduledTask expression, SessionSubmit[expr] is effectively SessionSubmit[ScheduledTask[expr,{Quantity[1,"Seconds"],1}]]; that is, expr is evaluated only once.

Examples

open allclose all

Basic Examples  (10)

Create a task to show a message dialog:

The task runs in the current session:

Create a task to show a message dialog after 2 seconds:

Use a Quantity object to specify time:

Display the result of evaluation after the task is finished:

Capture messages generated during the evaluation:

Format message output as a regular message:

Capture Print output from the evaluation:

Information about the task is available to the expression being evaluated:

Information about the task is available to event handlers:

Get notified when the task status changes:

Possible Issues  (1)

A task started by SessionSubmit evaluates the expression preemptively, as described in Advanced Dynamic Functionality. When Pause or a long-running evaluation is done preemptively, the kernel may appear to be locked up, or frozen, until this evaluation is finished.

This will cause the evaluator to pause periodically for 3 seconds, creating the effect of a locked up or busy kernel:

Remove the task to return the evaluator to a normal state:

Pause evaluated in the synchronous (main) evaluation thread allows preemptive evaluations to run:

Wolfram Research (2017), SessionSubmit, Wolfram Language function, https://reference.wolfram.com/language/ref/SessionSubmit.html (updated 2019).

Text

Wolfram Research (2017), SessionSubmit, Wolfram Language function, https://reference.wolfram.com/language/ref/SessionSubmit.html (updated 2019).

CMS

Wolfram Language. 2017. "SessionSubmit." Wolfram Language & System Documentation Center. Wolfram Research. Last Modified 2019. https://reference.wolfram.com/language/ref/SessionSubmit.html.

APA

Wolfram Language. (2017). SessionSubmit. Wolfram Language & System Documentation Center. Retrieved from https://reference.wolfram.com/language/ref/SessionSubmit.html

BibTeX

@misc{reference.wolfram_2024_sessionsubmit, author="Wolfram Research", title="{SessionSubmit}", year="2019", howpublished="\url{https://reference.wolfram.com/language/ref/SessionSubmit.html}", note=[Accessed: 22-November-2024 ]}

BibLaTeX

@online{reference.wolfram_2024_sessionsubmit, organization={Wolfram Research}, title={SessionSubmit}, year={2019}, url={https://reference.wolfram.com/language/ref/SessionSubmit.html}, note=[Accessed: 22-November-2024 ]}