In preparation for Python 3 support.

Rework how much of lock/threading is done,
make syntax both 2 and 3 compatible.
All tests pass with Python 3.3! (First rough cut).
Make sure it still works with 2.7.5