how to use supervisor:start_child?
Mickael Remond
mickael.remond@REDACTED
Tue Jan 10 14:31:15 CET 2006
* Dietmar Schaefer <dietmar@REDACTED> [2006-01-10 12:36:14 +0100]:
> Hi !
>
> I can't get this to work !
>
dddd> I have a supervisor:
>
> init([]) ->
>
> case whereis(sup) of
> undefined -> %% register only once
> register(sup, self());
> _ -> ok
> end,
>
> with a few ChildSpec:
> AChild = {xclock,{xclock,start_link,[]},
> permanent,2000,worker,[xclock]},
>
> StopChild = {stop_wrp,{stop_wrp,start_link,[]},
> permanent,2000,worker,[stop_wrp]},
>
> SimpleSup = {dynamic, {dynamic, start_link, []},
> transient, 2000, worker, [dynamic]},
>
>
> {ok,{{one_for_one,1,1}, [StopChild]}}.
>
>
> I I try to start_child
>
> supervisor:start_child(sup,[{dynamic, {dynamic, start_link,
> []},transient, 2000, worker, [dynamic]}]).
>
> I get
>
> {error,{invalid_child_spec,[{dynamic,{dynamic,start_link,[]},
> transient,
> 2000,
> worker,
> [dynamic]}]}}
>
> How can this be?
> ( it should be valid because I can use it in the return value of
> supervisor:init)
> ok,{{one_for_one,1,1}, [SimpeSup]}}.
Maybe you should try removing the surrounding list around the child spec:
With the surrounding list it tries to consider the list as an extra
parameter for the Child spec description defined at the start of the
supervisor.
The doc states:
start_child(SupRef, ChildSpec) -> Result
Types SupRef = Name | {Name, Node} | {global, Name} | pid()
Name = Node = atom()
ChildSpec = child_spec() | [term()]
Result = {ok, Child} | {ok, Child, Info} | {error,
Error}
Child = pid() | undefined
Info = term()
Error = already_present | {already_started, Child}
| term()
So maybe using
supervisor:start_child(sup,{dynamic, {dynamic, start_link,
[]},transient, 2000, worker, [dynamic]}).
can help. It might not be the only problem however.
I hope this helps,
--
Mickaël Rémond
http://www.process-one.net/
More information about the erlang-questions
mailing list