Piton.Pool (piton v0.5.0)

View Source

Piton.Pool is a GenServer which will be on charge of a pool of Piton.Ports.

Piton.Pool will launch as many Python processes as you define in pool_number and it will share them between all the request (executions) it receives. It is also protected from Python exceptions, therefore, if a Python code raises an exception that can close the port, a new one will be opened and added it to the pool.

Start a Pool

  {:ok, pool} = Piton.Pool.start_link([module: MyPoolPort, pool_number: pool_number], [])

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

module: Module which has to `use Piton.Port`
pool_number: number of available Pythons.

Run a Python code using the pool

  Piton.Pool.execute(pid_of_the_pool, elixir_function, list_of_arguments_of_elixir_function)

Timeout

Piton.Port.execution function has a timeout, this timeout will be passes as timeout to the Piton.Port.execution function.

Summary

Functions

Returns a specification to start this module under a supervisor.

It will execute the arguments in the given function of the given module using the given pool of ports.

It will return the number of available ports.

It will return the number of processes that are waiting for an available port.

Callback implementation for GenServer.init/1.

Functions

child_spec(init_arg)

Returns a specification to start this module under a supervisor.

See Supervisor.

execute(pid, python_function, python_arguments, timeout \\ 5000)

@spec execute(pid(), atom(), list(), timeout()) :: {:ok, any()} | {:error, any()}

It will execute the arguments in the given function of the given module using the given pool of ports.

get_number_of_available_ports(pid)

@spec get_number_of_available_ports(pid()) :: integer()

It will return the number of available ports.

get_number_of_waiting_processes(pid)

@spec get_number_of_waiting_processes(pid()) :: integer()

It will return the number of processes that are waiting for an available port.

init(list)

Callback implementation for GenServer.init/1.

start_link(args, opts)