Copy in pidfile.py

This is a direct copy of http://code.activestate.com/recipes/577911-context-manager-for-a-daemon-pid-file/