Try again if the connection gets in a bad state.
PEP-8 fixes and nitpicking.
Close cursor after use in contextmanager.

This seems to keep down sockets in use and mitigate the "socket.error:
[Errno 99] Cannot assign requested address"-issue.
Merge pull request #8 from johanlundberg/close_cursor_after_use

Close cursor after use