See a try/except/finally, particularly with an except clause like this, seems like a good place to use a context manager. I'm not sure if psycopg2's connection class supports being used like one, but it's worth a shot. For example:

    with psycopgs2.connect(*args) as conn:

If it doesn't support that, the [`closing`](http://docs.python.org/2/library/contextlib.html#contextlib.closing) wrapper can be used:

    with closing(psycopg2.connect(*args)) as conn: