Erlang 简单的一个孩子无法启动
我写了一些代码来测试simple_one_for_one supervisor,但它无法工作,代码是:Erlang 简单的一个孩子无法启动,erlang,erlang-supervisor,Erlang,Erlang Supervisor,我写了一些代码来测试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). %%--------------
-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\u simple\u one\u for\u one:start\u link()。
及
在erl shell中,它给我错误信息:
测试一个简单的测试一个测试一个:开始测试()。
**异常退出:{noproc,{gen_服务器,调用,
[test_simple_one_for_one,{start_child,[]},infinity]}
在gen_server函数中:call/3(gen_server.erl,第188行)
如果是您为测试编写的所有代码,请注意,当您注册一个主管子级时,您将提供一个{M,F,a}元组,它表示启动子级时调用的函数
在您的情况下,我认为它不能简单地找到fun\u test:run/1函数。调用start\u link然后start\u fun\u test时,代码似乎可以正常运行。此错误表示您在启动链接之前运行启动测试。
test_simple_one_for_one:start_fun_test().