simple_one_for_one孩子无法启动

时间:2012-04-26 11:27:27

标签: erlang supervisor

我编写了一些代码来测试simple_one_for_one主管,但它无法正常工作,代码是:

-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,[]},无限]}}        在函数gen_server中:call / 3(gen_server.erl,第188行)

1 个答案:

答案 0 :(得分:1)

如果这是你为测试编写的所有代码,请注意当你注册一个主管孩子时,你会得到一个{M,F,A}元组,它代表你启动孩子时所调用的功能。

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

相关问题