问题描述
我有一个测试模块来测试我的表
模块。
我的表
模块,当它终止时,调用这个:
I have a test module that tests my Table
module.My Table
module, when it terminates, calls this:
terminate(_, State = {Board, Status, Players}) ->
gen_server:stop(Board),
...stopping other processes,
io:format("Table Terminating.~p~n", [State]),
ok.
这是我的代码中唯一会阻止 code>进程。
This is the only part of my code that would stop a Board
process.
运行测试后,大约一分钟后我会得到这个:
After running my tests, I will get this after about a minute:
=ERROR REPORT==== 21-Jul-2017::22:28:40 ===
** Generic server <0.92.0> terminating
** Last message in was []
** When Server state == [[{spawn,x,none},
{recent,x,none},
{empty,null,none},
{empty,null,none},
{empty,null,none}],
[{empty,null,none},
{empty,null,none},
{empty,null,none},
{ridge,null,none},
{empty,null,none}],
[{empty,null,none},
{empty,null,none},
{ridge,null,none},
{empty,null,none},
{empty,null,none}],
[{empty,null,none},
{ridge,null,none},
{empty,null,none},
{empty,null,none},
{empty,null,none}],
[{empty,null,none},
{empty,null,none},
{empty,null,none},
{empty,null,none},
{spawn,o,none}]]
** Reason for termination ==
** {terminated,[{io,format,
[<0.90.0>,"Board.~p~n",
[[[{spawn,x,none},
{recent,x,none},
{empty,null,none},
{empty,null,none},
{empty,null,none}],
[{empty,null,none},
{empty,null,none},
{empty,null,none},
{ridge,null,none},
{empty,null,none}],
[{empty,null,none},
{empty,null,none},
{ridge,null,none},
{empty,null,none},
{empty,null,none}],
[{empty,null,none},
{ridge,null,none},
{empty,null,none},
{empty,null,none},
{empty,null,none}],
[{empty,null,none},
{empty,null,none},
{empty,null,none},
{empty,null,none},
{spawn,o,none}]]]],
[]},
{board,terminate,2,[{file,"board.erl"},{line,319}]},
{gen_server,try_terminate,3,
[{file,"gen_server.erl"},{line,629}]},
{gen_server,terminate,7,[{file,"gen_server.erl"},{line,795}]},
{proc_lib,init_p_do_apply,3,
[{file,"proc_lib.erl"},{line,247}]}]
像 Board
模块不正确地终止。 董事会
的终止是这样的:
which looks like the Board
module terminated improperly. The Board
's terminate is such:
terminate(normal, State) ->
io:format("Board.~p~n", [State]),
ok.
我试图在独立模块中复制这个内容, b
:
I tried to reproduce this in a standalone module, b
:
-module(b).
-compile(export_all).
init([]) -> {ok, {1, 2}}.
terminate(_, State) ->
io:format("Table Terminating.~p~n", [State]),
ok.
code_change(_OldVsn, State, _Extra) ->
{ok, State}.
handle_cast(_, State) ->
{noreply, State}.
handle_info(Msg, State) ->
io:format("Unexpected message: ~p~n",[Msg]),
{noreply, State}.
go() ->
gen_server:start_link(?MODULE, [], []).
不成功:
4> {ok,B} = b:go()。
{ok,< 0.74.0>}
5> gen_server:止动件(B)。
表终止{1,2}
我想知道的是,我应该寻找什么样的代码导致我的董事会得到 **终止原因==
停止的原因
** {终止
What I am wondering is, what kind of code should I look for that would cause my Board to get the ** Reason for termination ==** {terminated
reason for stopping?
完整的来源是:[email protected]:QuantumProductions / tunnel.git
Full source is here: [email protected]:QuantumProductions/tunnel.git
编辑:董事会包括这个
handle_call(stop, _From, State) ->
{stop, normal, shutdown_ok, State};
handle_call(_, _, Board) ->
{reply, {error, unrecognized, Board}, Board}.
编辑:我最好的猜测是 eunit
自动终止在其测试中创建的进程?
My best guess is eunit
is automatically terminated processes created within its tests?
推荐答案
为什么 borad
是 []
?根据您使用的代码 gen_server:stop / 1
调用 gen:stop / 1
调用 gen:stop / 3
调用,最后调用。当为gen_server调用 sys:terminate / 3
时,sys调用,它调用与 []
作为最后的消息!
Why borad
last message is []
? According to the code you used gen_server:stop/1
which calls gen:stop/1
which calls gen:stop/3
which calls proc_lib:stop/3
which finally calls sys:terminate/3
. When you call sys:terminate/3
for a gen_server, sys calls gen_server:system_terminate/4
and it calls gen_server:terminate/6
with []
as last message !
为什么 borad
以原因终止 {terminated,...}
?根据 io
代码, io:format / 2
最后调用,因为io进程已终止,在它成为 {terminate,...}
。
why borad
terminated with reason {terminated, ...}
? According to the io
code, io:format/2
finally calls io:execute_request/2
and you got this
because io process terminated and in here it becomes {terminated, ...}
.
这篇关于错误报告从终止的进程(预期是正常的)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!