piton v0.4.0 Piton.Port View Source

Piton.Port is a GenServer which will be on charge of the Python Port.

It is prepared to be the base of your own Port.

Make your own Port

defmodule MyPort do
  use Piton.PythonPort
  # rest of the code if it is need.
end

The arguments has to be in a Keyword List and it has to contain:

 path: Path to the folder where the python scripts are.
 python: python executable

If your port is going to run in a Piton.Pool (highly recommended) it has to have a start() function and it has not to be linked.

defmodule MyPoolPort do
  use Piton.Port
  def start(), do: MyPoolPort.start([path: Path.expand("python_folder"), python: "python"], [])
  def fun(pid, n), do: MyPoolPort.execute(pid, :functions, :fun, [n])
end

Run a Python code using directly the port (no pool)

iex> MyPort.execute(pid_of_the_port, python_module, python_function, list_of_arguments_of_python_function)