SnakeBridge.WithContext (SnakeBridge v0.15.0)

Copy Markdown View Source

Provides Python context manager support via with_python/2 macro.

Ensures __exit__ is always called, even on exception.

Example

SnakeBridge.with_python(file_ref) do
  SnakeBridge.Dynamic.call(file_ref, :read, [])
end

Summary

Functions

Calls enter on a Python context manager.

Calls exit on a Python context manager.

Executes a block with a Python context manager.

Functions

call_enter(ref, opts \\ [])

@spec call_enter(
  SnakeBridge.Ref.t() | map(),
  keyword()
) :: {:ok, term()} | {:error, term()}

Calls enter on a Python context manager.

call_exit(ref, exception, opts \\ [])

@spec call_exit(SnakeBridge.Ref.t() | map(), Exception.t() | nil, keyword()) ::
  {:ok, term()} | {:error, term()}

Calls exit on a Python context manager.

with_python(ref, list)

(macro)

Executes a block with a Python context manager.

Calls __enter__ before the block and guarantees __exit__ after, even if an exception occurs.