Rupyex.Native (Rupyex v0.1.0)

Copy Markdown View Source

Raw NIF bindings for the RustPython interpreter.

Nothing here blocks a scheduler: session_submit/3 only queues a request on the session's own OS thread and returns a job id, and the answer is delivered to the calling process as {tag, reply}.

Use Rupyex instead of calling these directly.

Precompiled

The NIF ships precompiled for the platforms below, so installing Rupyex needs no Rust toolchain. To build from source instead — for an unlisted platform, or to work on the crate — set RUPYEX_BUILD=1, or:

config :rustler_precompiled, :force_build, rupyex: true

Building needs Rust 1.93+ and takes a few minutes the first time. A debug build of RustPython is slow enough to be misleading, so the crate is always built in release mode.

Summary

Types

Opaque handle to a session thread.

Functions

Stop the interpreter thread and release its memory.

Abort a queued or running job.

Start an interpreter thread. Returns the session resource.

Whether the session still accepts requests.

Queue request; the reply is sent to the calling process as {tag, reply}.

Whether this build embeds the Python standard library.

Types

session()

@type session() :: reference()

Opaque handle to a session thread.

Functions

session_close(session)

@spec session_close(session()) :: :ok

Stop the interpreter thread and release its memory.

session_interrupt(session, job_id)

@spec session_interrupt(session(), non_neg_integer()) :: :ok

Abort a queued or running job.

session_open(opts)

@spec session_open(map()) :: session()

Start an interpreter thread. Returns the session resource.

session_open?(session)

@spec session_open?(session()) :: boolean()

Whether the session still accepts requests.

session_submit(session, tag, request)

@spec session_submit(session(), reference(), tuple() | atom()) ::
  {:ok, non_neg_integer()} | {:error, atom(), String.t()}

Queue request; the reply is sent to the calling process as {tag, reply}.

Returns {:ok, job_id} — the id session_interrupt/2 can abort — or {:error, :conversion | :closed, message}.

stdlib_available?()

@spec stdlib_available?() :: boolean()

Whether this build embeds the Python standard library.