繁体   English   中英

simple_one_for_one子无法启动

[英]simple_one_for_one child can not start

我写了一些代码来测试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()。 **异常退出:函数gen_server:call / 3中的{noproc,{gen_server,call,[test_simple_one_for_one,{start_child,[]},infinity]}}}(gen_server.erl,第188行)

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

就您而言,我认为它不能简单地找到fun_test:run / 1函数。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM