<div dir="ltr"><div>It is currently a general convention in asyncio to only catch Exception, not BaseException. I consider this a flaw and we should fix it, but it's unfortunately not so easy -- the tests will fail if you replace all occurrences of Exception with BaseException, and it is not always clear what's the right thing to do. E.g. catching KeyboardInterrupt may actually make it harder to stop a runaway asyncio app.</div><div><br></div><div>We should move this discussion to the issue tracker.<br></div></div><div class="gmail_extra"><br><div class="gmail_quote">On Mon, Jun 4, 2018 at 9:11 AM, Victor Stinner <span dir="ltr"><<a href="mailto:vstinner@redhat.com" target="_blank">vstinner@redhat.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Hi,<br>
<br>
I just read a recent bugfix in asyncio:<br>
<br>
<a href="https://github.com/python/cpython/commit/9602643120a509858d0bee4215d7f150e6125468" rel="noreferrer" target="_blank">https://github.com/python/<wbr>cpython/commit/<wbr>9602643120a509858d0bee4215d7f1<wbr>50e6125468</a><br>
<br>
+ try:<br>
+     await waiter<br>
+ except Exception:<br>
+     transport.close()<br>
+     raise<br>
<br>
Why only catching "except Exception:"? Why not also catching<br>
KeyboardInterrupt or MemoryError? Is it a special rule for asyncio, or<br>
a general policy in Python stdlib?<br>
<br>
For me, it's fine to catch any exception using "except:" if the block<br>
contains "raise", typical pattern to cleanup a resource in case of<br>
error. Otherwise, there is a risk of leaking open file or not flushing<br>
data on disk, for example.<br>
<br>
Victor<br>
______________________________<wbr>_________________<br>
Python-Dev mailing list<br>
<a href="mailto:Python-Dev@python.org">Python-Dev@python.org</a><br>
<a href="https://mail.python.org/mailman/listinfo/python-dev" rel="noreferrer" target="_blank">https://mail.python.org/<wbr>mailman/listinfo/python-dev</a><br>
Unsubscribe: <a href="https://mail.python.org/mailman/options/python-dev/guido%40python.org" rel="noreferrer" target="_blank">https://mail.python.org/<wbr>mailman/options/python-dev/<wbr>guido%40python.org</a><br>
</blockquote></div><br><br clear="all"><br>-- <br><div class="gmail_signature" data-smartmail="gmail_signature">--Guido van Rossum (<a href="http://python.org/~guido" target="_blank">python.org/~guido</a>)</div>
</div>