Just a general comment: creating lock files in a thread-safe way is hard, and I think there's a race condition here between the time the existence of the directory is checked and the `mkdir` call.  (We've at least had this bug in matplotlib on a few occasions).

I hate to suggest another dependency, but maybe we should look at `pylockfile` here.  It's certainly doing something much more sophisticated and likely better tested than this.