【发布时间】:2020-07-17 18:26:36
【问题描述】:
您好,我正在尝试运行 supervisor,其工作人员不是 gen_server(s)。
为简洁起见,我的主管与工人在同一模块中定义:
我不断收到此错误,我尝试将MFA 属性放入[ ] 无济于事。我还将ChildSpec 放入[ ]。
我错过了什么?
我不希望我的主管在启动它时有任何工人。
错误
> X=sup:start_link().
> ** exception error: no match of right hand side value {error,
> {bad_start_spec,[]}}
> in function sup:start_link/0 (c:/Erlang/ProcessPool/sup.erl, line 6)
> =CRASH REPORT==== 5-Apr-2020::22:20:32.918000 === crasher:
> initial call: supervisor:sup/1
> pid: <0.280.0>
> registered_name: []
> exception exit: {bad_start_spec,[]}
> in function gen_server:init_it/6 (gen_server.erl, line 358)
> ancestors: [<0.273.0>]
> message_queue_len: 0
> messages: []
> links: [<0.273.0>]
> dictionary: []
> trap_exit: true
> status: running
> heap_size: 376
> stack_size: 27
> reductions: 205 neighbours:
模块
-module(sup).
-behaviour(supervisor).
-compile([export_all]).
start_link() ->
{ok, Pid} = supervisor:start_link({local, ?MODULE}, ?MODULE, []),
Pid.
init(_Args) ->
RestartStrategy = {simple_one_for_one, 10, 60},
{ok, {RestartStrategy,[]}}.
add(Sup,Value)-> #adding child
ChildSpec = {
ch1,
{sup, start, [Value]},
permanent,
brutal_kill,
worker,
[ch1]
},
supervisor:start_child(Sup,ChildSpec).
start([Value])-> #child's start_link equivalent (non-genserver)
spawn_link(?MODULE,initworker,[self(),Value]).
initworker(From,Value)-> #child's init
receive
MSG->From ! {got_msg,Value,MSG}
end.
【问题讨论】: