[erlang-questions] gen_server noproc when trying to stop
Serge Aleynikov
saleyn@REDACTED
Sun Apr 20 16:40:27 CEST 2008
Since you use global registration, you have to address the server in
this way:
gen_server:call({global, ?SERVER}, Request).
In order to use the gen_server:call(?SERVER, Request) convention, use
locally registered servers:
gen_server:start_link({local, ?SERVER}, ?SERVER, [],[]).
db wrote:
> Can someone tell me why can't stop the gen_server?
>
> 9> myclnt:start().
> {ok,<0.90.0>}
> 10> myclnt:stop().
> ** exception exit: {noproc,{gen_server,call,[mysrvr,stop]}}
> in function gen_server:call/2
>
>
> -module(myclnt).
>
> -export([
> start/0,
> stop/0
> ]).
>
> -define(SERVER, mysrvr).
>
> start()->
> gen_server:start_link({global, ?SERVER}, ?SERVER, [],[]).
>
> stop()->
> gen_server:call(?SERVER, stop).
>
>
>
>
> -module(mysrvr).
>
> -behaviour(gen_server).
>
> -export([start_link/0]).
>
>
> -export([init/1, handle_call/3, handle_cast/2, handle_info/2,
> terminate/2, code_change/3]).
>
> -define(SERVER, ?MODULE).
>
> start_link() ->
> gen_server:start_link({global, ?SERVER}, ?MODULE, [], []).
>
> init([]) ->
> {ok,some}.
>
> handle_call({lookup}, _From, State) ->
> Reply = ok,
> io:format("_From: ~p State: ~p ~n",[_From, State]),
> {reply, Reply, State};
>
> handle_call(stop, _From, State)->
> io:format("_From: ~p State: ~p ~n",[_From, State]),
> {stop, normal, stopped, State}.
>
> handle_cast(_Msg, State) ->
> {noreply, State}.
>
> handle_info(_Info, State) ->
> {noreply, State}.
>
> terminate(_Reason, _State) ->
> ok.
>
> code_change(_OldVsn, State, _Extra) ->
> {ok, State}.
>
> Thank you,
More information about the erlang-questions
mailing list