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[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"the version of the external system
    "Kernel"the Jupyter kernel name (e.g. "IFSharp")
    "Executable"the name of the executable to run to start scripts with
    "ReturnType"type of object to return ("String", "Expression", ...)
    "Prolog"code to run before commands evaluated with this session
    "Epilog"code to run after commands evaluated with this 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
    "Jupyter"Jupyter kernel
  • 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  (3)

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:

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:

Introduced in 2017
 (11.2)