def rename_to_temp(filename):
    """*Thread-safe* renames file to temporary filename. Returns new name"""
    with _rename_to_temp_lock:
        root, ext = os.path.splitext(filename)
        if len(ext) > 0:
            ext = ext[1:]  # the dot (".") is originally included
        new_name = new_filename(root, ext)
        os.rename(filename, new_name)
        return new_name
def rename_to_temp ( filename ) : with _rename_to_temp_lock : root , ext = os . path . splitext ( filename ) if len ( ext ) > 0 : ext = ext [ 1 : ] new_name = new_filename ( root , ext ) os . rename ( filename , new_name ) return new_name
*Thread-safe* renames file to temporary filename. Returns new name