True ({local, Name} -> register locally, not globally, with Name) but you have to be careful if having two instances alive in the same time is acceptable or not.<div><br>Steve, let's put it this way it's better to start processes under supervisor specially if you want to benefit from standard restarting strategies, it keeps your application cleaner.</div>
<div>(as a hack, your case can also be solved by a monitor in the gen_server init before starting the gen_server</div><div><div> erlang:monitor(process, my_gen_event),</div><div> receive</div><div> {'DOWN', Ref, process, Pid, Reason}-></div>
<div> ok</div><div> end,</div><div>)</div><div>But using supervisor is much cleaner and safer, and easier to design with in my opinion</div><div class="gmail_quote">On Thu, Jun 2, 2011 at 10:23 AM, Ladislav Lenart <span dir="ltr"><<a href="mailto:lenartlad@volny.cz">lenartlad@volny.cz</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">Hello.<br>
<br>
I am by no means an expert on the topic but I would like to point out<br>
that the only reason you get {already_started, ...} error is because<br>
you attempt to register the helper process with {local, ...}. If it is<br>
a helper, there should be no reason for it to be globally accessible.<br>
And if it wasn't registered, the gen_server would be restarted without<br>
issues creating new helper process. The old helper would die eventually<br>
just as you expect it to.<br>
<br>
<br>
Ladislav Lenart<div class="im"><br>
<br>
<br>
On 2.6.2011 09:15, Steve Strong wrote:<br>
</div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div class="im">
Yeah, that makes perfect sense and would obviously solve the problem.<br>
<br>
The reason we'd gone down this path was that we had a number of "sub" processes (the gen_event just being one example) that we felt would be "polluting" the supervisor; these sub-processes were just<br>
helpers of the primary gen_servers that the supervisor was controlling - using a start_link in the primary gen_servers felt like a very clean and easy way of spinning up these other processes in a way<br>
that (we thought) would still be resilient to failures.<br>
<br>
The thing that bit us was that we naively thought that, due to the sub-process being linked, it would die when the parent died. Of course, it does, but its death is asynchronous to the notification<br>
that the supervisor receives and hence it may well still be alive (doomed, but alive) when the supervisor begins the restart cycle. Our servers don't crash that often, and when they do this race<br>
condition is was rarely seen, which was reinforced our misconceptions. The only thing that does surprise me is how many times the supervisor can go round the restart loop before the doomed process<br>
finally exits - we have seen it thrash round this loop about 1000 times before the supervisor itself finally fails; I guess it's just down to how things are being scheduled by the VM, and in those<br>
cases we were just getting unlucky.<br>
<br>
Sounds like best-practice within the OTP world is to have everything started via a supervisor - is that a fair comment?<br>
<br>
Cheers,<br>
<br>
Steve<br>
<br>
--<br>
Steve Strong, Director, id3as<br>
<a href="http://twitter.com/srstrong" target="_blank">twitter.com/srstrong</a><br>
<br>
On Wednesday, 1 June 2011 at 23:57, Ahmed Omar wrote:<br>
<br>
</div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div class="im">
Agree with Roberto, you should put under supervisor. Regarding your case, i would guess you are trapping exit in your init in my_gen_event?<br>
<br></div><div class="im">
On Wed, Jun 1, 2011 at 11:15 PM, Roberto Ostinelli <<a href="mailto:roberto@widetag.com" target="_blank">roberto@widetag.com</a> <mailto:<a href="mailto:roberto@widetag.com" target="_blank">roberto@widetag.com</a>>> wrote:<br>
</div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div class="im">
hi steve,<br>
<br>
your gen_event should be started by your supervisor too. in this case, since you specified a one_for_all behaviour, when gen_server crashes, gen_event will be restarted too.<br>
<br>
r.<br>
<br>
<br>
_______________________________________________<br>
erlang-questions mailing list<br>
</div><a href="mailto:erlang-questions@erlang.org" target="_blank">erlang-questions@erlang.org</a> <mailto:<a href="mailto:erlang-questions@erlang.org" target="_blank">erlang-questions@erlang.org</a>><div class="im">
<br>
<a href="http://erlang.org/mailman/listinfo/erlang-questions" target="_blank">http://erlang.org/mailman/listinfo/erlang-questions</a><br>
<br>
</div></blockquote><div class="im">
<br>
<br>
<br>
--<br>
Best Regards,<br>
- Ahmed Omar<br>
<a href="http://nl.linkedin.com/in/adiaa" target="_blank">http://nl.linkedin.com/in/adiaa</a><br>
Follow me on twitter<br></div>
@spawn_think <<a href="http://twitter.com/#!/spawn_think" target="_blank">http://twitter.com/#!/spawn_think</a>><br>
<br>
</blockquote><div class="im">
<br>
<br>
<br>
_______________________________________________<br>
erlang-questions mailing list<br>
<a href="mailto:erlang-questions@erlang.org" target="_blank">erlang-questions@erlang.org</a><br>
<a href="http://erlang.org/mailman/listinfo/erlang-questions" target="_blank">http://erlang.org/mailman/listinfo/erlang-questions</a><br>
</div></blockquote>
<br>
<br>
</blockquote></div><br><br clear="all"><br>-- <br>Best Regards,<br>- Ahmed Omar<div><a href="http://nl.linkedin.com/in/adiaa" target="_blank">http://nl.linkedin.com/in/adiaa</a></div><div>Follow me on twitter</div><div><a href="http://twitter.com/#!/spawn_think" target="_blank">@spawn_think</a></div>
<br>
</div>