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)

and with

import tables

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