|
Hi,
I have an application that I want to stop. In terminate() of one of the processes I save some state to an xml file (with xmerl:export() and file:write_file()). When this process terminates by itself all is well, and the file is saved. But when I call application:stop(myapp) the call to xmerl:export() (in terminate) never returns and the state is not saved. There are no error reports in the log, just the usual info report about myapp having exited. I have put a try/catch (throw/exit/error) around the xmerl:export() with some io:format() calls but nothing comes out. Anybody have a suggestion? Thanks, Gijsbert _______________________________________________ erlang-questions mailing list [hidden email] http://www.erlang.org/mailman/listinfo/erlang-questions |
|
Make sure your process is trapping exits. If it isn't, the process will die immediately when the supervisor calls exit(Pid, shutdown). BR, Ulf W Gijsbert de Haan skrev: > Hi, > > I have an application that I want to stop. In terminate() of one of the > processes I save some state to an xml file (with xmerl:export() and > file:write_file()). When this process terminates by itself all is well, > and the file is saved. > But when I call application:stop(myapp) the call to xmerl:export() (in > terminate) never returns and the state is not saved. There are no error > reports in the log, just the usual info report about myapp having > exited. I have put a try/catch (throw/exit/error) around the > xmerl:export() with some io:format() calls but nothing comes out. > > Anybody have a suggestion? > Thanks, > Gijsbert > _______________________________________________ > erlang-questions mailing list > [hidden email] > http://www.erlang.org/mailman/listinfo/erlang-questions erlang-questions mailing list [hidden email] http://www.erlang.org/mailman/listinfo/erlang-questions |
|
The process is indeed trapping exits.
I see my debug io:format() from my terminate() function before the call to xmerl:export/3, but not the ones after. In the following code (edited) I see 'before_xmerl_export', but nothing after (related to that process): terminate(Reason, State) -> ?D(Reason), {memory, Memory} = erlang:process_info(self(), memory), error_logger:info_msg( "~p session '~s' memory usage ~B\n", [self(), Name, Memory]), Prolog = ["<?xml version=\"1.0\" encoding=\"UTF-8\"?>"], ?D(Prolog), Xml = getXml(State), ?D(before_xmerl_export), try xmerl:export( [Xml], xmerl_xml, [#xmlAttribute{name = prolog, value = Prolog}]) of StrData -> ?D(before_list_to_binary), Data = list_to_binary(StrData), case file:write_file(Name2, Data) of ok -> error_logger:info_msg("~p session '~s' saved\n", [self(), Name2]); {error, Error} -> error_logger:error_msg( "~p session '~s' NOT saved\nError ~p\n", [self(), Name2, Error]) end catch throw:X -> ?D(throw), ?D(X); exit:X -> ?D(exit), ?D(X); error:X -> ?D(error), ?D(X) end, ok. On Tue, 10 Jun 2008 15:45:51 +0200, "Ulf Wiger (TN/EAB)" <[hidden email]> said: > > Make sure your process is trapping exits. > If it isn't, the process will die immediately when > the supervisor calls exit(Pid, shutdown). > > BR, > Ulf W > > Gijsbert de Haan skrev: > > Hi, > > > > I have an application that I want to stop. In terminate() of one of the > > processes I save some state to an xml file (with xmerl:export() and > > file:write_file()). When this process terminates by itself all is well, > > and the file is saved. > > But when I call application:stop(myapp) the call to xmerl:export() (in > > terminate) never returns and the state is not saved. There are no error > > reports in the log, just the usual info report about myapp having > > exited. I have put a try/catch (throw/exit/error) around the > > xmerl:export() with some io:format() calls but nothing comes out. > > > > Anybody have a suggestion? > > Thanks, > > Gijsbert > > _______________________________________________ > > erlang-questions mailing list > > [hidden email] > > http://www.erlang.org/mailman/listinfo/erlang-questions erlang-questions mailing list [hidden email] http://www.erlang.org/mailman/listinfo/erlang-questions |
|
In reply to this post by Ulf Wiger (TN/EAB)
Hi,
My terminate() function is not finishing after application:stop(myapp). I am wondering if my terminate() function takes too long and is getting killed before it finishes. I have tried to increase the Shutdown timeout in the child specification but it seems to have no influence. The process is started by supervisor:start_child(session_sup, Opts), session_sup is specified as: {session_sup, {supervisor, start_link, [{local, session_sup},?MODULE,[session]]}, permanent, infinity, supervisor, [] } And the init that returns the spec for the child is this: init([Module]) -> {ok, {_SupFlags = {simple_one_for_one, ?MAX_RESTART, ?MAX_TIME}, [{undefined, {Module, start_link, []}, temporary, 2000, worker, [] }] } }. On Tue, 10 Jun 2008 15:45:51 +0200, "Ulf Wiger (TN/EAB)" <[hidden email]> said: > > Make sure your process is trapping exits. > If it isn't, the process will die immediately when > the supervisor calls exit(Pid, shutdown). > > BR, > Ulf W > > Gijsbert de Haan skrev: > > Hi, > > > > I have an application that I want to stop. In terminate() of one of the > > processes I save some state to an xml file (with xmerl:export() and > > file:write_file()). When this process terminates by itself all is well, > > and the file is saved. > > But when I call application:stop(myapp) the call to xmerl:export() (in > > terminate) never returns and the state is not saved. There are no error > > reports in the log, just the usual info report about myapp having > > exited. I have put a try/catch (throw/exit/error) around the > > xmerl:export() with some io:format() calls but nothing comes out. > > > > Anybody have a suggestion? > > Thanks, > > Gijsbert > > _______________________________________________ > > erlang-questions mailing list > > [hidden email] > > http://www.erlang.org/mailman/listinfo/erlang-questions erlang-questions mailing list [hidden email] http://www.erlang.org/mailman/listinfo/erlang-questions |
|
This post has NOT been accepted by the mailing list yet.
In reply to this post by Gijsbert de Haan
mypp:init() ->
process_flag(trap_exit,true), <------Try add this line |
| Powered by Nabble | Edit this page |
