[erlang-questions] Can not start many children with simple_one_for_one
Barco You
barcojie@REDACTED
Tue Jul 30 04:53:49 CEST 2013
Dear Forks,
I have a supervisor who will start children with simple_one_for_one
strategy. First of all I have server process who starts the mentioned
supervisor by using {ok, Pid} = supervisor:start_child(Supsup, ?SPEC), and
then I add the children under the mentioned supervisor one by one also with
supervisor:start_child(Pid, Args), but only the first child can be started
and the rest children just got "process already started" error message.
What's wrong I made? the snippets of the codes as following:
-module(spider_sup).
-behaviour(supervisor).
-export([start_link/0]). %% API.
-export([init/1]). %% supervisor.
-define(SUPERVISOR, ?MODULE).
%% API.
start_link() ->
supervisor:start_link({local, ?SUPERVISOR}, ?MODULE, []).
%% supervisor.
init([]) ->
MaxRestart = 5,
MaxTime = 60,
{ok, {{simple_one_for_one, MaxRestart, MaxTime},
[{spider,
{spider, start_link, []},
permanent,
120,
worker,
[spider]}]}}.
----------------------------------------------------------------------------------------------------------
-module(spider).
-behavior(gen_fsm).
-export([start_link/1]).
-export([init/1,
event1/2,
handle_event/3,
handle_sync_event/4,
code_change/4,
terminate/3,
handle_info/3]).
start_link(Code) ->
gen_fsm:start_link({local, ?MODULE}, ?MODULE, Code, []).
init(Code) ->
io:format("~p Starting~n",[Code]),
{ok, event1, Code, 10000}.
---------------------------------------------------------------------------------------------------
%snippet from the server process
start_spiders(_Pid, []) ->
ok;
start_spiders(Pid, [HCode | TCode]) ->
supervisor:start_child(Pid, [HCode]),
start_spiders(Pid, TCode).
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20130730/3280403e/attachment.htm>
More information about the erlang-questions
mailing list