StartExternalSession

StartExternalSession["sys"]

starts an external session using the external evaluator sys, returning an external session object.

StartExternalSession[{"sys",opts}]

uses the options opts for the external evaluator.

StartExternalSession[DatabaseReference[ref]]

uses the database specified by ref to start a database session.

StartExternalSession[assoc]

starts the external evaluator specified by assoc.

StartExternalSession[systype]

specifies that output from the external evaluator should be converted to the specified type.

Details

  • StartExternalSession starts an external process that can be used to implement an external evaluator session in which there are multiple evaluations requested by ExternalEvaluate.
  • To be usable with ExternalEvaluate, language installations must have a standard 0MQ library installed for that particular language, as well as a "JSON" library.
  • In StartExternalSession[assoc], elements of the association can include:
  • "System"the external system or language to start
    "Version"version of the external system to use (e.g. "3.6")
    "Kernel"the Jupyter kernel name (e.g. "IFSharp")
    "Target"the target to use for evaluating code
    "ReturnType"type of object to return ("String", "Expression", ...)
    "Prolog"code to run before the command
    "Epilog"code to run after the command
    "SessionProlog"code to run before the session
    "SessionEpilog"code to run after the session
  • "System" is the only required key; all others are optional.
  • In StartExternalSession[sys], possible choices of sys include:
  • "Python"Python
    "NodeJS"JavaScript running through Node.js
    "Julia"Julia
    "Ruby"Ruby
    "R"R
    "Shell"Bash, Sh, Zsh, ...
    "Jupyter"Jupyter kernel
    "SQL"SQL database
    "SQL-JDBC"SQL database using JDBC
  • Possible settings for "type" in StartExternalSession[sys"type",], or for "ReturnType", include:
  • "Expression"attempt to convert to a Wolfram Language expression
    "String"give the raw string output by the external evaluator
  • The possible settings for target in StartExternalSession[{sys,"Target"target},] depend on sys, and include:
  • "path"path to a language executable
    DatabaseReference[]an SQL database connection
    SQLConnection[]an SQL-JDBC database connection
  • Typically, StartExternalSession uses the setting "ReturnType""Expression".
  • FindExternalEvaluators gives a dataset of evaluator systems that can be used.
  • ExternalSessions gives a list of active external sessions.
  • DeleteObject[ExternalSessionObject[]] kills and removes an external session started by StartExternalSession.

Examples

open allclose all

Basic Examples  (2)

Start an external Python session, automatically discovering any usable installations:

Evaluate code in the session:

Stop the session with DeleteObject:

Start a session using Python Version 3:

Verify the version:

End the session:

Scope  (4)

Multiple external sessions can be run simultaneously:

Delete the session objects:

Start an external Python session using the executable in /usr/bin/python2.7:

Use the session for multiple calls to ExternalEvaluate:

Stop the session with DeleteObject:

Start an external session and import a library at the beginning of the session:

Evaluate a function from the imported library:

Delete the session object:

Start a session that imports a library and sets x to 0, then increments x each ExternalEvaluate call:

Define a command to compute the Factorial of x in the session:

Evaluate the command 10 times:

Verify that the result is the first 10 Factorial values:

Delete the session object:

Properties & Relations  (4)

Each session runs in its own process:

The process IDs for each session are different:

Delete the session objects:

If only the language is specified, the first evaluator returned by FindExternalEvaluators is used:

Stop the session:

Start a database session:

Run a query:

Manually close the session:

External language cells implicitly call StartExternalSession:

x=2

A new session has been started:

By default, all cells of a given system use that session:

x*x

End the session so that subsequent evaluations start in a new session:

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

Text

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

CMS

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

APA

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

BibTeX

@misc{reference.wolfram_2022_startexternalsession, author="Wolfram Research", title="{StartExternalSession}", year="2020", howpublished="\url{https://reference.wolfram.com/language/ref/StartExternalSession.html}", note=[Accessed: 03-December-2022 ]}

BibLaTeX

@online{reference.wolfram_2022_startexternalsession, organization={Wolfram Research}, title={StartExternalSession}, year={2020}, url={https://reference.wolfram.com/language/ref/StartExternalSession.html}, note=[Accessed: 03-December-2022 ]}