[erlang-questions] Can not start many children with simple_one_for_one

James Aimonetti james@REDACTED
Tue Jul 30 05:00:31 CEST 2013


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA256

On 07/29/2013 07:53 PM, Barco You wrote:
> 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).
> 
> 
> 
> _______________________________________________ erlang-questions
> mailing list erlang-questions@REDACTED 
> http://erlang.org/mailman/listinfo/erlang-questions
> 

It appears your gen_fsm is registering itself as a named process. So
the first succeeds because the name isn't registered; subsequent
attempts will not start additional children as the name is no longer
available. Try using gen_fsm:start_link/3 [0] instead.

[0]
http://erldocs.com/R15B/stdlib/gen_fsm.html?i=2&search=gen_fsm%20start#start_link/3

- -- 
James Aimonetti
Distributed Systems Engineer / DJ MC_

2600hz | http://2600hz.com
sip:james@REDACTED
tel: 415.886.7905
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.11 (GNU/Linux)
Comment: Using GnuPG with Thunderbird - http://www.enigmail.net/

iF4EAREIAAYFAlH3LE8ACgkQ54NxaUq7OmBHqwD/Vu+If3oUpqgmHlooOW6ZwZ3z
34YJKrncaBJDOxRINloBAIx25ZL3migY3y29jZ8hS4Oho4NY1n4uwjDCe8QFeu8k
=u5w5
-----END PGP SIGNATURE-----



More information about the erlang-questions mailing list