<div dir="ltr"><div class="gmail_extra"><div class="gmail_quote" style="font-size:12.8px"><span class="gmail-im">On Fri, Sep 30, 2016 at 12:18 PM, Grzegorz Junka <span dir="ltr"><<a href="mailto:list1@gjunka.com" target="_blank">list1@gjunka.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div bgcolor="#FFFFFF"><span class="gmail-m_1467578595304841122gmail-"><br><div class="gmail-m_1467578595304841122gmail-m_-219337052318166156moz-cite-prefix">On 30/09/2016 01:25, Mark Bucciarelli wrote:<br></div><blockquote type="cite"><div dir="ltr">I have a program that does the following:<div><br></div><div>- start gen_event, naming it "dispatcher"</div><div>- spawn a process</div><div>- send 60 message to process then a stop message</div><div>- exit</div><div><br></div></div></blockquote></span></div></blockquote></span><div>... </div><span class="gmail-im"><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div bgcolor="#FFFFFF"><span class="gmail-m_1467578595304841122gmail-"><blockquote type="cite"><div dir="ltr"><div></div><div>But when I run it from inside the interpreter, <br></div><div><div><br></div><div>    > simulation:start().</div><div><br></div><div>I see:</div><div><p class="gmail-m_1467578595304841122gmail-m_-219337052318166156gmail-p1">** exception error: no such process or port</p><p class="gmail-m_1467578595304841122gmail-m_-219337052318166156gmail-p1">(which is gen_event saying hey, I can't notify the Pid with that name</p><p class="gmail-m_1467578595304841122gmail-m_-219337052318166156gmail-p1">because it's gone.)</p><p class="gmail-m_1467578595304841122gmail-m_-219337052318166156gmail-p1"><br></p><p class="gmail-m_1467578595304841122gmail-m_-219337052318166156gmail-p1">Why don't I get that error output when I run from the console?</p><br></div></div></div></blockquote><br></span>If you spawn the dispatcher from the shell then it will be linked to the shell process. So, won't be actually gone.<span class="gmail-m_1467578595304841122gmail-HOEnZb"><font color="#888888"><br><br></font></span></div></blockquote><div><br></div><div><br></div></span><div>My question was not precise, but your answer was still correct I believe.</div><div><br></div><div>I was stopping the gen_event when the main loop ended.  But the child process keeps running, and its call to gen_event:notify/2 fails.</div><div><br></div><div>So, if I understand correctly, inside the interpreter the child is linked to the interpreter shell when the main loop stops.  Then, when the child crashes it sends an exit signal to its one link, the shell.</div><div><br></div><div>Thanks, I have gained some understanding of how fast async messages and mailbox buffers require you to think in a different way.</div><div><br></div><div>Here's the code of the main loop for reference.</div><div><br></div><div><div>-module(simulation).</div><div>    </div><div>-export([start/0]).</div><div>    </div><div>% The clock.</div><div>tictoc(60, Pid) -></div><div>    Pid ! stop,  </div><div>    ok;</div><div>tictoc(TimeInTics, Pid) -></div><div>    Pid ! tic,</div><div>    tictoc(TimeInTics + 1, Pid).</div><div>    </div><div>% Spawn child process and start clock ticking.</div><div>run_clock() -> </div><div>    Pid = spawn_link(stoplight, start, [0, {30, 30, 6}]),</div><div>    tictoc(0, Pid).</div><div>    </div><div>% Simulation entry point.</div><div>start() -></div><div>    {ok, _Pid} = gen_event:start({local, dispatcher}),</div><div>    ok = gen_event:add_handler(<wbr>dispatcher, logger, []),</div><div>    run_clock(),</div><div>    gen_event:stop(dispatcher),</div><div>    io:put_chars("main routine is done.\n").</div></div></div><div class="gmail-yj6qo gmail-ajU" style="margin:2px 0px 0px;font-size:12.8px"><div id="gmail-:3up" class="gmail-ajR" tabindex="0"><img class="gmail-ajT" src="https://ssl.gstatic.com/ui/v1/icons/mail/images/cleardot.gif" style="opacity: 0.3;"></div></div><div class="gmail-adL" style="font-size:12.8px"><span class="gmail-im"><br>Mark<br clear="all"><div><br></div>-- <br><div class="gmail-m_1467578595304841122gmail_signature"><div dir="ltr"><div dir="ltr"><div><span style="font-size:12.8px">Blogging at <a href="http://markbucciarelli.com/" target="_blank">markbucciarelli.com</a></span><br></div><div>Tweeting @mbucc</div></div></div></div></span></div>
</div></div>