[erlang-questions] the supervisor 's error when the child process occur 'function_clause' error!!
谈广云
fw339tgy@REDACTED
Wed Apr 15 15:28:25 CEST 2015
hi joe,
when i use erlang laguage , i meet a problem.
i use supervisor to manage the child process.
test module is supervisor , the child is my_bank moudle is gen_server's callback .
the code is :
%%%%test module
-module(test).
-behaviour(supervisor).
%% ====================================================================
%% API functions
%% ====================================================================
%% Supervisor callbacks
-export([init/1]).
-export([start_link/0,start_child/0]).
%% ====================================================================
%% Internal functions
%% ====================================================================
init([]) ->
process_flag(trap_exit, true),
Poker = {my_bank, {my_bank, start, []}, permanent, brutal_kill, worker, [my_bank]},
{ok, {{one_for_one, 5, 10}, [Poker]}}.
start_link() ->
supervisor:start_link({local, ?MODULE}, ?MODULE, []).
%%%%% =============
%%%% my_bank module
-module(my_bank).
-behaviour(gen_server).
-export([start/0]).
%% gen_server callbacks
-export([init/1, handle_call/3, handle_cast/2, handle_info/2,
terminate/2, code_change/3]).
-compile(export_all).
-define(SERVER, ?MODULE).
start() -> gen_server:start_link({local, ?MODULE}, ?MODULE, [], []).
stop() -> gen_server:call(?MODULE, stop).
new_account(Who) -> gen_server:call(?MODULE, {new, Who}).
deposit(Who, Amount) -> gen_server:call(?MODULE, {add, Who, Amount}).
withdraw(Who, Amount) -> gen_server:call(?MODULE, {remove, Who, Amount}).
init([]) ->
%process_flag(trap_exit, true),
%gen_server:start({local, my_bank2}, my_bank2, [], []),
io:format("=====start===== my_bank ~n"),
{ok, ets:new(?MODULE,[])}.
%%%%%%
i call gen_server:call(my_bank,{new2,inzaghi}).
gen_server:call(my_bank,{new,inzaghi}) is right .
the my_bank will occur a error "function_clause".
when the my_bank process occur ' function_clause' error, the supervisor can not restat the my_bank process , and quit with no error.
This problem has troubled me for a long time, very much look forward to your reply.
thanks.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20150415/f26d26c5/attachment.htm>
More information about the erlang-questions
mailing list