I cannot overwrite h5 file with dicttoh5

I get the error message:

OSError: Unable to create file (unable to truncate a file which is already open)

I tried closing the file with

file = h5py.File(fpath)
file.close()

and with

import tables
tables.file._open_files.close_all()

But I still get this error message… (it works when I change the file name to a non-existing one)