Use with-statements to acquire locks.

We can use with-statements now that we've dropped support
for Python 2.4.
Modern exception-handling syntax in ha_tools.

Now that we've dropped support for Python 2.4.