Rupyex.Server (Rupyex v0.1.0)

Copy Markdown View Source

A supervised owner for a long-lived session.

A session lives as long as the struct that refers to it, so something has to hold on to it. This server does exactly that and nothing else:

children = [
  {Rupyex.Server, name: MyApp.Python, init: "import json"}
]

Supervisor.start_link(children, strategy: :one_for_one)

{:ok, 3} = Rupyex.Server.eval(MyApp.Python, "1 + 2")

Python code does not run inside this process: session/1 hands the session back and the caller talks to the interpreter thread directly, so one slow snippet cannot make the server a bottleneck. When calling in a tight loop, fetch the session once and pass it to Rupyex yourself.

Summary

Functions

Returns a specification to start this module under a supervisor.

Run Python source in the server's session. See Rupyex.eval/3.

The session this server owns.

Start a server.

Functions

call(server, target, args \\ [], kwargs \\ [])

@spec call(GenServer.server(), String.t(), [term()], keyword() | map()) ::
  {:ok, term()} | {:error, Rupyex.Error.t()}

See Rupyex.call/4.

child_spec(init_arg)

Returns a specification to start this module under a supervisor.

See Supervisor.

eval(server, code, opts \\ [])

@spec eval(GenServer.server(), String.t(), keyword()) ::
  {:ok, term()} | {:error, Rupyex.Error.t()}

Run Python source in the server's session. See Rupyex.eval/3.

run(server, code, opts \\ [])

@spec run(GenServer.server(), String.t(), keyword()) ::
  {:ok, Rupyex.Result.t()} | {:error, Rupyex.Error.t()}

See Rupyex.run/3.

session(server)

@spec session(GenServer.server()) :: Rupyex.Session.t()

The session this server owns.

start_link(opts)

@spec start_link(keyword()) :: GenServer.on_start()

Start a server.

Takes the options of Rupyex.Session.open/1, plus :name for the process.