'Close this file, saving the lockfile over the original.
:note: If this method fails, it will attempt to delete the lockfile.
However, it is not guaranteed to do so (e.g. if a filesystem
becomes suddenly read-only), which will prevent future writes to
this file until the lockfile is removed manually.
:raises OSError: if the original file could not be overwritten. The
lock file is still closed, so further attempts to write to the same
file object will raise ValueError.'

def close(self):

    if self._closed:
        return
    self._file.close()
    try:
        os.rename(self._lockfilename, self._filename)
    except OSError as e:
        if ((sys.platform == 'win32') and (e.errno == errno.EEXIST)):
            _fancy_rename(self._lockfilename, self._filename)
        else:
            raise
    finally:
        self.abort()
