{'EXIT',#Port<number>,normal} errors on startup

defmodule TheApp.Application do
  require Logger
  use Application

  def start(_type, _args) do
    :logger.add_handlers(:the_app)

    Print.text("Initiating TheApp \n")

    children = [
      TheAppDB.Repo,
      Supervisor.PyOperatorManager
    ]

    opts = [strategy: :one_for_one, name: TheApp.Supervisor]
    Supervisor.start_link(children, opts)
  end
end

defmodule Supervisor.PyOperatorManager do
  use Supervisor

  @timeout 60_000

  def start_link(_) do
    Supervisor.start_link(__MODULE__, [], name: __MODULE__)
  end

  @impl true
  def init(_) do
    Process.flag(:trap_exit, true)

    children = [
      :poolboy.child_spec(:py_pool,
        name: {:local, :py_pool},
        worker_module: Server.PyOperator,
        size: 10,
        max_overflow: 5
      )
    ]

    Supervisor.init(children, strategy: :one_for_one)
  end

  def launch(data \\ [], py_module, py_lambda) do
    :poolboy.transaction(
      :py_pool,
      fn pid ->
        GenServer.call(pid, {data, py_module, py_lambda}, @timeout)
      end,
      @timeout
    )
  end
end

defmodule Server.PyOperator do
  use GenServer
  use Export.Python

  def start_link(_) do
    GenServer.start_link(__MODULE__, %{})
  end

  @impl true
  def init(state) do
    Process.flag(:trap_exit, true)

    priv_path = Path.join(:code.priv_dir(:arbit), "python")
    {:ok, py} = Python.start_link(python_path: priv_path)
    {:ok, Map.put(state, :py, py)}
  end

  @impl true
  def handle_call({args, py_module, py_lambda}, _from, %{py: py} = state) do
    results = Python.call(py, py_module, py_lambda, [args])

    {:reply, results, state}
  end

  @impl true
  def terminate(_reason, %{py: py}) do
    Python.stop(py)
    :ok
  end
end

2021-10-06T22:23:46.065683+00:00 info: Supervisor: {<0.377.0>,'Elixir.DBConnection.ConnectionPool.Pool'}. Started: id={'Elixir.Postgrex.Protocol',<0.376.0>,1},pid=<0.378.0>.
2021-10-06T22:23:46.084583+00:00 info: Supervisor: {<0.377.0>,'Elixir.DBConnection.ConnectionPool.Pool'}. Started: id={'Elixir.Postgrex.Protocol',<0.376.0>,2},pid=<0.379.0>.
2021-10-06T22:23:46.084832+00:00 info: Supervisor: {<0.377.0>,'Elixir.DBConnection.ConnectionPool.Pool'}. Started: id={'Elixir.Postgrex.Protocol',<0.376.0>,3},pid=<0.380.0>.
2021-10-06T22:23:46.085016+00:00 info: Supervisor: {<0.377.0>,'Elixir.DBConnection.ConnectionPool.Pool'}. Started: id={'Elixir.Postgrex.Protocol',<0.376.0>,4},pid=<0.381.0>.
2021-10-06T22:23:46.085196+00:00 info: Supervisor: {<0.377.0>,'Elixir.DBConnection.ConnectionPool.Pool'}. Started: id={'Elixir.Postgrex.Protocol',<0.376.0>,5},pid=<0.382.0>.
2021-10-06T22:23:46.085350+00:00 info: Supervisor: {<0.377.0>,'Elixir.DBConnection.ConnectionPool.Pool'}. Started: id={'Elixir.Postgrex.Protocol',<0.376.0>,6},pid=<0.383.0>.
2021-10-06T22:23:46.085475+00:00 info: Supervisor: {<0.377.0>,'Elixir.DBConnection.ConnectionPool.Pool'}. Started: id={'Elixir.Postgrex.Protocol',<0.376.0>,7},pid=<0.384.0>.
2021-10-06T22:23:46.085600+00:00 info: Supervisor: {<0.377.0>,'Elixir.DBConnection.ConnectionPool.Pool'}. Started: id={'Elixir.Postgrex.Protocol',<0.376.0>,8},pid=<0.385.0>.
2021-10-06T22:23:46.085713+00:00 info: Supervisor: {<0.377.0>,'Elixir.DBConnection.ConnectionPool.Pool'}. Started: id={'Elixir.Postgrex.Protocol',<0.376.0>,9},pid=<0.386.0>.
2021-10-06T22:23:46.085815+00:00 info: Supervisor: {<0.377.0>,'Elixir.DBConnection.ConnectionPool.Pool'}. Started: id={'Elixir.Postgrex.Protocol',<0.376.0>,10},pid=<0.387.0>.
2021-10-06T22:23:46.085936+00:00 info: Supervisor: {<0.377.0>,'Elixir.DBConnection.ConnectionPool.Pool'}. Started: id={'Elixir.Postgrex.Protocol',<0.376.0>,11},pid=<0.388.0>.
2021-10-06T22:23:46.086109+00:00 info: Supervisor: {<0.377.0>,'Elixir.DBConnection.ConnectionPool.Pool'}. Started: id={'Elixir.Postgrex.Protocol',<0.376.0>,12},pid=<0.389.0>.
2021-10-06T22:23:46.086287+00:00 info: Supervisor: {<0.377.0>,'Elixir.DBConnection.ConnectionPool.Pool'}. Started: id={'Elixir.Postgrex.Protocol',<0.376.0>,13},pid=<0.390.0>.
2021-10-06T22:23:46.086477+00:00 info: Supervisor: {<0.377.0>,'Elixir.DBConnection.ConnectionPool.Pool'}. Started: id={'Elixir.Postgrex.Protocol',<0.376.0>,14},pid=<0.391.0>.
2021-10-06T22:23:46.086656+00:00 info: Supervisor: {<0.377.0>,'Elixir.DBConnection.ConnectionPool.Pool'}. Started: id={'Elixir.Postgrex.Protocol',<0.376.0>,15},pid=<0.392.0>.
2021-10-06T22:23:46.087901+00:00 info: Supervisor: {local,'Elixir.TheAppDB.Repo'}. Started: id='Elixir.DBConnection.ConnectionPool',pid=<0.376.0>.
2021-10-06T22:23:46.088211+00:00 info: Supervisor: {local,'Elixir.TheApp.Supervisor'}. Started: id='Elixir.TheAppDB.Repo',pid=<0.375.0>.
2021-10-06T22:23:46.090726+00:00 info: Supervisor: {local,inet_gethost_native_sup}. Started: pid=<0.396.0>,mfa={inet_gethost_native,init,[[]]}.
2021-10-06T22:23:46.090961+00:00 info: Supervisor: {local,kernel_safe_sup}. Started: id=inet_gethost_native_sup,pid=<0.395.0>.
2021-10-06T22:23:46.278295+00:00 error: 'Elixir.Server.PyOperator' <0.398.0> received unexpected message in handle_info/2: {'EXIT',#Port<0.24>,normal}
2021-10-06T22:23:46.401591+00:00 error: 'Elixir.Server.PyOperator' <0.401.0> received unexpected message in handle_info/2: {'EXIT',#Port<0.26>,normal}
2021-10-06T22:23:46.530950+00:00 error: 'Elixir.Server.PyOperator' <0.403.0> received unexpected message in handle_info/2: {'EXIT',#Port<0.28>,normal}
2021-10-06T22:23:46.736844+00:00 error: 'Elixir.Server.PyOperator' <0.405.0> received unexpected message in handle_info/2: {'EXIT',#Port<0.30>,normal}
2021-10-06T22:23:46.900071+00:00 error: 'Elixir.Server.PyOperator' <0.407.0> received unexpected message in handle_info/2: {'EXIT',#Port<0.32>,normal}
2021-10-06T22:23:47.039102+00:00 error: 'Elixir.Server.PyOperator' <0.409.0> received unexpected message in handle_info/2: {'EXIT',#Port<0.34>,normal}
2021-10-06T22:23:47.197723+00:00 error: 'Elixir.Server.PyOperator' <0.411.0> received unexpected message in handle_info/2: {'EXIT',#Port<0.36>,normal}
2021-10-06T22:23:47.365769+00:00 error: 'Elixir.Server.PyOperator' <0.413.0> received unexpected message in handle_info/2: {'EXIT',#Port<0.38>,normal}
2021-10-06T22:23:47.550171+00:00 error: 'Elixir.Server.PyOperator' <0.415.0> received unexpected message in handle_info/2: {'EXIT',#Port<0.40>,normal}
2021-10-06T22:23:47.730449+00:00 error: 'Elixir.Server.PyOperator' <0.417.0> received unexpected message in handle_info/2: {'EXIT',#Port<0.42>,normal}

How and why is {'EXIT',#Port<number>,normal} being triggered?

Because that is how port informs controlling process that spawned process has ended.

2 Likes