petehunt/PyMySQL — pull request #148 by rfk (2013-06-03 03:49:12+00:00)
Title: Remove unjustified uses of bare 'except' clause

PyMySQL contains several uses of a bare 'except' clause, like this::

try:
do_something()
except:
handle_error()

Using bare except is almost always a bad idea, as it captures whole-program control flow exceptions like SystemExit, KeyboardInterrupt and gevent.Timeout. This PR changes it to use the "except Exception" form, which should capture anything of interest while leaving control flow exceptions untouched.

As concrete motivation, I found this because the existing code doesn't cooperate with gevent timeouts. Code like this::

with gevent.Timeout(5):
cursor.execute("SOME LONG RUNNING SQL STATEMENT")

Doesn't time out correctly, because PyMySQL swallows the gevent.Timeout exception and converts it into a DBAPI error. Ideally it would pass through the gevent.Timeout exception unchanged.