Snex.Env (Snex v0.4.1)

Copy Markdown View Source

An environment (%Snex.Env{}) is an Elixir-side reference to a Python-side variable context in which the Python code is executed.

This module is not intended to be used directly. Instead, you would use the Snex.make_env/3 to create environments, Snex.pyeval/4 to use them.

The only exceptions are Snex.Env.disable_gc/1, which can be called to opt into manual management of the environment lifecycle, and Snex.Env.interpreter/1, which can be used to get the interpreter the environment is bound to.

See Snex module documentation for more details.

Summary

Types

t()

Elixir-side reference to a Python-side environment.

Functions

Disables automatic garbage collection for the given environment.

Returns the interpreter that the given environment belongs to.

Types

id()

@opaque id()

t()

@type t() :: %Snex.Env{
  encoding_opts: Snex.Serde.encoding_opts(),
  id: id(),
  interpreter: pid(),
  port: port(),
  ref: :erlang.nif_resource() | nil
}

Elixir-side reference to a Python-side environment.

The id field can be used to identify the environment, but its underlying type can change without notice. All other fields should be considered an implementation detail and never used directly.

Functions

disable_gc(env)

@spec disable_gc(t()) :: t()

Disables automatic garbage collection for the given environment.

This function can only be called on the node that created the environment. It can be called multiple times on the same environment.

Once garbage collection is disabled, the environment can only be cleaned up by calling Snex.destroy_env/1, or by stopping the interpreter altogether.

interpreter(env)

@spec interpreter(t()) :: Snex.Interpreter.server()

Returns the interpreter that the given environment belongs to.