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
    "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
  • 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  (3)

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

In[1]:=
Click for copyable input
Out[1]=

Evaluate some code:

In[2]:=
Click for copyable input
Out[2]=

Stop the session with DeleteObject:

In[3]:=
Click for copyable input

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

In[1]:=
Click for copyable input
Out[1]=

Sessions are persistent across calls to ExternalEvaluate:

In[2]:=
Click for copyable input
In[3]:=
Click for copyable input
Out[3]=

Stop the session with DeleteObject:

In[4]:=
Click for copyable input

Specifying the language only will automatically find a suitable installation, regardless of version:

In[1]:=
Click for copyable input
Out[1]=

Get the version automatically used:

In[2]:=
Click for copyable input
Out[2]=

Start a session with a specific version of the system with the "Version" key:

In[3]:=
Click for copyable input
Out[3]=
In[4]:=
Click for copyable input
Out[4]=

Code in some language versions may run, while it may fail in other versions:

In[5]:=
Click for copyable input
Out[5]=
In[6]:=
Click for copyable input
Out[6]=

Stop the sessions:

In[7]:=
Click for copyable input

Scope  (2)

See Also

ExternalEvaluate  ExternalSessions  ExternalSessionObject  FindExternalEvaluators  StartProcess  Install  DeleteObject

Tutorials

Introduced in 2017
(11.2)