tweak locking and add simple test.

Moved `sys.exit(1)` out of `lock.py` and added simple test to make sure locking works as intended.