Maxximiliann

Maxximiliann

(EXIT) no process: the process is not alive or there's no process currently associated with the given name

defmodule The_App.Application do
  require Logger
  use Application

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

    Print.text("Initiating The_App \n")

    children = [
      The_AppDB.Repo
    ]

    opts = [strategy: :one_for_one, name: The_App.Supervisor]
    Supervisor.start_link(children, opts)
  end
end
defmodule Supervisor.PyOperatorManager do
  use Supervisor

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

  @impl true
  def init(_) do
    children = [
      :poolboy.child_spec(:py_pool,
        name: {:local, :py_pool},
        worker_module: Server.PyOperator,
        size: 4,
        max_overflow: 2
      )
    ]

    Supervisor.init(children, strategy: :one_for_one)
  end
  
  def launch() do
    :poolboy.transaction(:py_pool, fn pid ->
      GenServer.call(pid, {"hello_world", "main", "Hello"})
    end)
  end
end
defmodule Server.PyOperator do
  use GenServer
  use Export.Python

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

  def init(state) do
    Process.flag(:trap_exit, true)
    priv_path = Path.join(:code.priv_dir(:the_app), "python")
    {:ok, py} = Python.start_link(python_path: priv_path)
    {:ok, Map.put(state, :py, py)}
  end

  def handle_call({py_module, py_lambda, data}, _from, %{py: py} = state) do
    result = Python.call(py, py_module, py_lambda, [data])
    {:reply, result, state}
  end

  def terminate(_reason, %{py: py}) do
    Python.stop(py)
    :ok
  end
end
Interactive Elixir (1.12.2) - press Ctrl+C to exit (type h() ENTER for help)
iex(1)> Supervisor.PyOperatorManager.launch()
** (exit) exited in: :gen_server.call(:py_pool, {:checkout, #Reference<0.4022030713.2998403074.45553>, true}, 5000)
    ** (EXIT) no process: the process is not alive or there's no process currently associated with the given name, possibly because its application isn't started
    (stdlib 3.15.1) gen_server.erl:247: :gen_server.call/3
    (poolboy 1.5.2) /home/source/Desktop/The_App/deps/poolboy/src/poolboy.erl:63: :poolboy.checkout/3
    (poolboy 1.5.2) /home/source/Desktop/The_App/deps/poolboy/src/poolboy.erl:82: :poolboy.transaction/3
iex(1)> Supervisor.PyOperatorManager.start_link([])
** (EXIT from #PID<0.367.0>) shell process exited with reason: shutdown: failed to start child: :py_pool
    ** (EXIT) an exception was raised:
        ** (MatchError) no match of right hand side value: {:error, {:already_started, #PID<0.379.0>}}
            (poolboy 1.5.2) /home/source/Desktop/The_App/deps/poolboy/src/poolboy.erl:283: :poolboy.new_worker/1
            (poolboy 1.5.2) /home/source/Desktop/The_App/deps/poolboy/src/poolboy.erl:304: :poolboy.prepopulate/3
            (poolboy 1.5.2) /home/source/Desktop/The_App/deps/poolboy/src/poolboy.erl:153: :poolboy.init/3
            (stdlib 3.15.1) gen_server.erl:423: :gen_server.init_it/2
            (stdlib 3.15.1) gen_server.erl:390: :gen_server.init_it/6
            (stdlib 3.15.1) proc_lib.erl:226: :proc_lib.init_p_do_apply/3

What exactly is causing these errors and how are they properly addressed?

Marked As Solved

Maxximiliann

Maxximiliann

defmodule The_App.Application do
  require Logger
  use Application

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

    Print.text("Initiating The_App \n")

    children = [
      The_AppDB.Repo,
      Supervisor.PyOperatorManager
    ]

    opts = [strategy: :one_for_one, name: The_App.Supervisor]
    Supervisor.start_link(children, opts)
  end
end
defmodule Supervisor.PyOperatorManager do
  use Supervisor

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

  @impl true
  def init(_) do
    children = [
      :poolboy.child_spec(:py_pool,
        name: {:local, :py_pool},
        worker_module: Server.PyOperator,
        size: 4,
        max_overflow: 2
      )
    ]

    Supervisor.init(children, strategy: :one_for_one)
  end
  
  def launch() do
    :poolboy.transaction(:py_pool, fn pid ->
      GenServer.call(pid, {"foo", "main", "Hello"})
    end)
  end
end
defmodule Server.PyOperator do
  use GenServer
  use Export.Python

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

  def init(state) do
    Process.flag(:trap_exit, true)
    priv_path = Path.join(:code.priv_dir(:the_app), "python")
    {:ok, py} = Python.start_link(python_path: priv_path)
    {:ok, Map.put(state, :py, py)}
  end

  def handle_call({py_module, py_lambda, data}, _from, %{py: py} = state) do
    result = Python.call(py, py_module, py_lambda, [data])
    {:reply, result, state}
  end

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

Modifications:

  • Added Supervisor.PyOperatorManager to The_App.Application’s children
  • Removed name: __MODULE__ from Supervisor.PyOperatorManager.start_link(_)

Where Next?

Popular in Questions Top

9mm
I am constructing a JSON object (map) and I need to conditionally set a field. I’m trying to write proper elixir-way code… and I’m at a l...
New
Harrisonl
We have an ECS cluster with 4 services, where each task joins a single cluster, via discovery ECS discovery service. Currently when I de...
New
mcarvalho
What is the difference between System.get_env and Application.get_env? For example, what are best practices to use one versus another.
New
ovidiubadita
Hey all, I discovered Elixir and I love it. I always wanted to learn a functional programming and I intended to go for Haskell, but afte...
New
jason.o
In the code below, if the create action is not set to accept “extra_key” as an input, it errors out with a message shown above. Is there ...
New
komlanvi
Hi everyone, I was playing with phoenix liveView but I run into an issue. I have a form and want to validate each input text when the te...
New
joaquinalcerro
Hi there, I am working with Ecto-Postgresql and I need to call all of the records from a specific table but the table has 40,000 records...
New
openscript
Hello! Sorry for this astonishing simple question, but I’m really stuck. I try to set up the intellij-elixir plugin, but I don’t know ho...
New
earth10
Hi, I’m just starting to build a side-project with Elixir and Phoenix and doing some basic test with Elixir alone. What strikes me is th...
New
vonH
In asking this question I am more interested about the expressiveness of the language itself and less concerned about the availability of...
New

Other popular topics Top

AstonJ
Posting this to see if we can make things easier for people to get into Neovim. If you use Neovim and have a favourite distro please let ...
New
albydarned
Hello all! I am typing this post from my new MacBook Pro with the M1 chip. I’m loving it so far, and will probably use it as my daily dr...
New
chrismccord
Phoenix 1.4.0 released Phoenix 1.4 is out! This release ships with exciting new features, most notably with HTTP2 support, improved deve...
688 31013 112
New
belgoros
I’m not a pro in using Regex and can’t figure out why the following behaviour happens, especially if we take into account the difference ...
New
josevalim
Hi everyone, One of the features added to Elixir early on to help integration with Erlang code was the idea of overridable function defi...
New
joeerl
Hello again - after a longish gap I’ve decided I really must dig into Elixir and see what’s been happening here - so I have a few questio...
New
vrod
I am using the Starship cross-shell prompt – it seems pretty nice, but I get some errors: [WARN] - (starship::utils): Executing command ...
New
saif
Hello everyone, Long time lurker first time poster here. I’ve recently begun working on Elixir full-time again! :raised_hands: It’s been...
New
KronicDeth
Elixir plugin for JetBrain’s IntelliJ Platform (including Rubymine) This is a plugin that adds support for Elixir to JetBrains IntelliJ...
289 36352 110
New
openscript
Hello! Sorry for this astonishing simple question, but I’m really stuck. I try to set up the intellij-elixir plugin, but I don’t know ho...
New

Latest on Elixir Forum

Elixir Forum

We're in Beta

About us Mission Statement