@contextmanager
def safe_concurrent_creation(target_path):
 safe_mkdir_for(target_path)
 tmp_path = u'{}.tmp.{}'.format(target_path, uuid.uuid4().hex)
 try:
  (yield tmp_path)
 finally:
  if os.path.exists(tmp_path):
   safe_concurrent_rename(tmp_path, target_path)

@ contextmanager def safe_concurrent_creation ( target_path ) : safe_mkdir_for ( target_path ) tmp_path = u'{}.tmp.{}' . format ( target_path , uuid . uuid4 ( ) . hex ) try : ( yield tmp_path ) finally : if os . path . exists ( tmp_path ) : safe_concurrent_rename ( tmp_path , target_path )
a contextmanager that yields a temporary path and renames it to a final target path when the contextmanager exits .