Elixir:目前没有与给定名称关联的进程

时间:2018-11-15 19:01:32

标签: elixir

Elixir给我一个错误,指出进程名称与某件事有关,但是,我不知道该如何解决。

我的mix.exs文件如下:

defmodule Crowller.MixProject do
  use Mix.Project

  def project do
    [
      app: :crowller,
      version: "0.1.0",
      elixir: "~> 1.7",
      start_permanent: Mix.env() == :prod,
      deps: deps()
    ]
  end

  # Run "mix help compile.app" to learn about applications.
  def application do
    [mod: {Crowller.Application, []}]
  end

  # Run "mix help deps" to learn about dependencies.
  defp deps do
    [
      {:poison, "~> 3.1"}, # json library
      {:httpoison, "~> 1.4"}, # json library
    ]
  end
end

这是我的Crowller.Application模块:

defmodule Crowller.Application do
  use Application
  import Crowller.Data
  import Crowller.Controller

  def start(_, _) do
    key_groups = struct(Crowller.Data.ServerList).keygroups
    for index <- 0..length(key_groups)-1 do
      Task.start(fn() ->
        matched_group(Enum.at(key_groups, index))
      end)
    end
  end

end

这是我得到的错误:

=INFO REPORT==== 15-Nov-2018::18:54:04.741174 ===
    application: crowller
    exited: {bad_return,
                {{'Elixir.Crowller.Application',start,[normal,[]]},
                 {'EXIT',
                     {undef,
                         [{'Elixir.Crowller.Application',start,[normal,[]],[]},
                          {application_master,start_it_old,4,
                              [{file,"application_master.erl"},
                               {line,277}]}]}}}}
    type: permanent
** (exit) exited in: GenServer.call(Mix.ProjectStack, {:get_and_update, #Function<14.775349/1 in Mix.ProjectStack.printable_app_name/0>}, 30000)
    ** (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
    (elixir) lib/gen_server.ex:914: GenServer.call/3
    (mix) lib/mix/shell/io.ex:15: Mix.Shell.IO.print_app/0
    (mix) lib/mix/shell/io.ex:34: Mix.Shell.IO.error/1
    (mix) lib/mix/tasks/app.start.ex:135: Mix.Tasks.App.Start.ensure_all_started/2
    (elixir) lib/enum.ex:765: Enum."-each/2-lists^foreach/1-0-"/2
    (elixir) lib/enum.ex:765: Enum.each/2
    (mix) lib/mix/tasks/app.start.ex:114: Mix.Tasks.App.Start.start/2
    (mix) lib/mix/tasks/app.start.ex:86: Mix.Tasks.App.Start.run/1
*** Shell process terminated! (^G to start new job) ***
{"Kernel pid terminated",application_controller,"{application_start_failure,crowller,{bad_return,{{'Elixir.Crowller.Application',start,[normal,[]]},{'EXIT',{undef,[{'Elixir.Crowller.Application',start,[normal,[]],[]},{application_master,start_it_old,4,[{file,\"application_master.erl\"},{line,277}]}]}}}}}"}
Kernel pid terminated (application_controller) ({application_start_failure,crowller,{bad_return,{{'Elixir.Crowller.Application',start,[normal,[]]},{'EXIT',{undef,[{'Elixir.Crowller.
Application',start,

1 个答案:

答案 0 :(得分:2)

在您的Mixfile中,您指定的项目是带有监督树的Erlang application

[mod: {Crowller.Application, []}]

这意味着您的Crowller.Application模块必须实现一个start/2回调来启动应用程序监视树。当您已经实现该方法时,实际上并没有启动任何过程或对其进行监督according to the specification

  

start/2回调必须产生并链接管理程序,并返回{:ok, pid}{:ok, pid, state},其中pid是管理程序的PID,状态是可选的应用程序状态。 args是赋予:mod选项的元组的第二个元素。


您可以使用Supervisor助手来做到这一点:

defmodule Crowller.Application do
  use Application

  def start(_type, _args) do
    children = []     # Add your subprocesses here (if any)
    Supervisor.start_link(children, strategy: :one_for_one)
  end
end