time it takes to reastart gen_server
Gunilla Arendt
gunilla@REDACTED
Wed Jan 4 14:42:10 CET 2006
You don't have a gen_server, you have a plain Erlang process.
The process calls "gen_server:call(self(), stop)" when the port
is closed, thus sending a gen_server request to itself. But since
the process is not a gen_server (and does not handle the request),
no reply is received and the function call does not return until
the default gen_server timeout expires (incidentally, after 5 seconds)
and only then does the process terminate.
Instead of calling "gen_server:call(self(), stop)", simply let
the process terminate by -- for example -- returning an atom 'stop':
...
receive
{'EXIT',Port,Reason} ->
io:format(...),
stop;
...
Also, I recommend you read "Design Principles" in the Erlang/OTP
documentation to learn more about generic servers.
/ Gunilla
Dietmar Schaefer wrote:
> Happy new year !
>
>
> I am trying to develop a gen_server which starts a unix process
>
>
> do(ExtPrg) -> process_flag(trap_exit,
> true), %% to get informed when process terminates
> Port = open_port({spawn, ExtPrg}, [{packet, 2}]), %% ExtProg
> also includes parameter
> loop(Port).
>
>
>
> loop(Port) ->
> receive
> {'EXIT',Port,Reason} -> io:format("external program exited~n
> Reason=~p Port=~p~n",[Reason,Port]), %port program died
> gen_server:call(self(),stop) %% all work is done -
> go home
> end.
>
>
>
> This gen_server is supervised by a supervisor.
>
> init(_Args) -> case whereis(watchdog) of
> undefined -> %% register only once
> register(watchdog, self());
> _ -> ok
> end,
>
>
> Xclock = {xclock,{xclock,start_link,["/usr/X11R6/bin/xclock"]},
> permanent,brutal_kill,worker,[xclock]},
>
> Xterm = {xterm,{xterm,start_link,["/usr/bin/xterm"]},
> permanent,brutal_kill,worker,[xterm]},
>
> {ok,{{one_for_one,1,6}, [Xclock,Xterm]}}.
>
>
> It takes 5 seconds to restart my xclock after I closed it.
>
> How can I fasten it up ?
>
> regards
>
>
> Dietmar
>
>
More information about the erlang-questions
mailing list