importing withlock script from upstream
adding some basic unit tests
Python3 compatibility changes