Handle parallel calls of makedirs with locks
Fix compatibility with python 2.6