【问题标题】:simple_one_for_one child can not startsimple_one_for_one 孩子无法启动
【发布时间】:2012-05-07 03:05:44
【问题描述】:

我写了一些代码来测试simple_one_for_one supervisor,但它不能工作,代码是:

-module(test_simple_one_for_one).

-behaviour(supervisor).

%% API
-export([start_link/0, start_fun_test/0]).

%% Supervisor callbacks
-export([init/1]).

-define(SERVER, ?MODULE).

%%--------------------------------------------------------------------
start_link() ->
    {ok, Pid} = supervisor:start_link({local, ?SERVER}, ?MODULE, []).

start_fun_test() ->
    supervisor:start_child(test_simple_one_for_one, []).

init([]) ->
    RestartStrategy = simple_one_for_one,
    MaxRestarts = 1000,
    MaxSecondsBetweenRestarts = 3600,

    SupFlags = {RestartStrategy, MaxRestarts, MaxSecondsBetweenRestarts},

    Restart = permanent,
    Shutdown = 2000,
    Type = worker,

    AChild = {fun_test_sup, {fun_test, run, []},
          Restart, Shutdown, Type, [fun_test]},
    io:format("start supervisor------ ~n"),
    {ok, {SupFlags, [AChild]}}.

当我跑步时

test_simple_one_for_one:start_link().

test_simple_one_for_one:start_fun_test().

在 erl shell 中,它给了我错误:

test_simple_one_for_one:start_fun_test()。 ** 异常退出:{noproc,{gen_server,call, [test_simple_one_for_one,{start_child,[]},infinity]}} 在函数 gen_server:call/3 (gen_server.erl, line 188)

【问题讨论】:

  • 当 start_link 和 start_fun_test 被调用时,代码看起来还可以并且工作得很好。这个错误告诉你在 start_link 之前运行 start_fun_test。

标签: erlang erlang-supervisor


【解决方案1】:

如果这是您为测试编写的所有代码,请注意,当您注册监督子时,您会提供一个 {M, F, A} 元组,它表示您启动子时调用的函数。

在你的情况下,我认为它不能简单地找到 fun_test:run/1 函数。

【讨论】:

    猜你喜欢
    • 2014-12-09
    • 2017-05-02
    • 2020-07-22
    • 2012-11-04
    • 2016-06-11
    • 2016-08-16
    • 1970-01-01
    • 2016-05-03
    • 1970-01-01
    相关资源
    最近更新 更多