Robust endless loop for server written in Python : <p>I write a server which handles events and uncaught exceptions during handling the event must not terminate the server.</p>

<p>The server is a single non-threaded python process.</p>

<p>I want to terminate on these errors types:</p>

<ul>
<li>KeyboardInterrupt</li>
<li>MemoryError</li>
<li>...</li>
</ul>

<p>The list of built in exceptions is long: <a href="https://docs.python.org/2/library/exceptions.html" rel="noreferrer">https://docs.python.org/2/library/exceptions.html</a></p>

<p>I don't want to re-invent this exception handling, since I guess it was done several times before.</p>

<p>How to proceed? </p>

<ol>
<li>Have a white-list: A list of exceptions which are ok and processing the next event is the right choice</li>
<li>Have a black-list: A list of exceptions which indicate that terminating the server is the right choice.</li>
</ol>

<p>Hint: This question is not about running a unix daemon in background. It is not about double fork and not about redirecting stdin/stdout :-)</p>
