[erlang-questions] Why is the spawn_link not working?

Alexandre Beaulne alexandre.beaulne@REDACTED
Tue Jan 14 03:53:40 CET 2014


Hi again!

It is not process that fails who receives the {'EXIT', Pid, Reason}
signal/message, but rather the processes that are linked to the failing
process. I added a print statement to you
example<http://bin.cakephp.org/raw/469809960> and
it behaves quite as expected:

1> Pid = spawn(mph_drop, mph_drop, []).
<0.35.0>
2> Pid ! {moon, 23}.
Received the input to drop.
On moon, a fall of 23 meters yields a velocity of 19.19077538460069 mph.
{moon,23}
3> Pid ! {moon, asdf}.
Received the input to drop.
Received EXIT signal from drop process, respawning!
{moon,asdf}
4>
=ERROR REPORT==== 14-Jan-2014::10:46:58 ===
Error in process <0.36.0> with exit value:
{badarith,[{drop,fall_velocity,2,[{file,"drop.erl"},{line,26}]},{drop,drop,0,[{file,"drop.erl"},{line,16}]}]}

Admittedly the error report is a bit confusing as everything worked as
planned.


On Tue, Jan 14, 2014 at 9:26 AM, Yves S. Garret
<yoursurrogategod@REDACTED>wrote:

> Hmm... here is my updated code, but the exit that comes via a link does
> not seem to get trapped!
> http://bin.cakephp.org/view/936550339
>
> This is what happens:
> http://bin.cakephp.org/view/554367077
>
>
> On Sun, Jan 12, 2014 at 7:48 PM, Bob Ippolito <bob@REDACTED> wrote:
>
>> When two processes are linked, failures (abnormal exits) propagate from
>> one to the other, ensuring that both die. This is not done by way of
>> messages, but by an exit signal. These EXIT messages are only sent to
>> processes that are trapping exits. See
>> http://www.erlang.org/doc/reference_manual/processes.html#id83186 and
>> refer to "Receiving Exit Signals".
>>
>> In your case, the code in one process fails, which causes the other
>> process to fail, so it can't print anything because there is no more
>> process and it never received an exit message. A solution to this problem
>> would be to use the trap_exit process flag (as is the case with
>> supervisors), or use a monitor instead of a link.
>>
>> -bob
>>
>>
>>
>> On Sun, Jan 12, 2014 at 4:36 PM, Yves S. Garret <
>> yoursurrogategod@REDACTED> wrote:
>>
>>> Hello,
>>>
>>> I've recently created the following two modules from a book:
>>> http://bin.cakephp.org/view/1356260281
>>> http://bin.cakephp.org/view/13533081
>>>
>>> Now, when I send Pid ! {moon, asdf}. I get the following output:
>>> 39> Pid ! {moon, w}.
>>> Received the input and sending now.
>>> Received the input to drop.
>>> {moon,w}
>>>
>>> =ERROR REPORT==== 12-Jan-2014::19:31:38 ===
>>> Error in process <0.162.0> with exit value:
>>> {badarith,[{drop,fall_velocity,2,[{file,"drop.erl"},{line,27}]},{drop,drop,0,[{file,"drop.erl"},{line,17}]}]}
>>>
>>> Why am I not seeing this line run?
>>> io:format("FAILURE: ~p died because of ~p.~n~n", [Pid, Reason]);
>>>
>>> _______________________________________________
>>> erlang-questions mailing list
>>> erlang-questions@REDACTED
>>> http://erlang.org/mailman/listinfo/erlang-questions
>>>
>>>
>>
>
> _______________________________________________
> erlang-questions mailing list
> 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/20140114/78d81c20/attachment.htm>


More information about the erlang-questions mailing list