[erlang-questions] 回复: Will terminate of gen_server be called in this situation?

goofansu goofan.su@REDACTED
Thu Jul 11 09:48:13 CEST 2013


Hi,

I have the same question before and you can see my question here: http://stackoverflow.com/questions/16693922/simple-one-for-one-can-only-be-terminated-if-appointed-shutdown-strategy-to-brut.

As you've described, I created an example on github: https://github.com/goofansu/sofo-example, and can print "terminate" as expected.

My operations like following:

$ erl -pa ebin -s myapp
Erlang R15B01 (erts-5.9.1) [source] [64-bit] [smp:4:4] [async-threads:0] [kernel-poll:false]

Eshell V5.9.1  (abort with ^G)
1> {ok, ChildPid} = myapp_sup:start_child().
{ok,<0.37.0>}
2> ChildPid ! stop.
terminate
stop
3>


If you use myapp_sup:stop_child(ChildPid). It will terminate directly.  

--  
Kind Regards
goofansu


在 2013年7月11日星期四,下午2:41,Bin Wang 写道:

> Hi,
>  
> I found my terminate in gen_server is not been called in this
> situation, did I miss something?
>  
> Part of the code is:
>  
> handle_info(stop, State) ->
> {stop, normal, State}.
>  
> terminate(_, _) ->
> io:format(user, "termiate~n", []).
>  
> And I have set process_flag(trap_exit, true) in "init", and this
> gen_server is under a supervisor tree. It is a simple_one_for_one
> supervisor and the spec is like this, "client" here is the module
> name:
>  
> {ok, {{simple_one_for_one, 3, 10}, [{
> client,
> {client, start, []},
> transient,
> 10000,
> worker,
> [client]
> }
> ]}}.
>  
> When I send some info with stop to the gen_server, it did stop, but
> the terminate function is not called. Anybody have some ideas? Thanks!
> _______________________________________________
> erlang-questions mailing list
> erlang-questions@REDACTED (mailto:erlang-questions@REDACTED)
> http://erlang.org/mailman/listinfo/erlang-questions
>  
>  


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20130711/cf164b11/attachment.htm>


More information about the erlang-questions mailing list