There is a code segment as follows
try:
f = h5py.File(filename, 'w-')
except:
os.remove(filename)
f = h5py.File(filename, 'w-')
Running the program getting the error related to the above code segment. I think it is because the file was not closed. Googling the similar error message, it seems that it can be solved using "with" statement, but I am not sure how to modify the above code segment.
OSError Traceback (most recent call last)
<ipython-input-19-1f1f9c5eb3dd> in vid_to_hdf(En, start, end, chunk)
9 try:
---> 10 f = h5py.File(filename, 'w-')
11 except:
~\AppData\Local\Continuum\anaconda3\envs\fastai-py37\lib\site-packages\h5py\_hl\files.py in __init__(self, name, mode, driver, libver, userblock_size, swmr, rdcc_nslots, rdcc_nbytes, rdcc_w0, track_order, **kwds)
407 fapl, fcpl=make_fcpl(track_order=track_order),
--> 408 swmr=swmr)
409
~\AppData\Local\Continuum\anaconda3\envs\fastai-py37\lib\site-packages\h5py\_hl\files.py in make_fid(name, mode, userblock_size, fapl, fcpl, swmr)
176 elif mode in ['w-', 'x']:
--> 177 fid = h5f.create(name, h5f.ACC_EXCL, fapl=fapl, fcpl=fcpl)
178 elif mode == 'w':
h5py\_objects.pyx in h5py._objects.with_phil.wrapper()
h5py\_objects.pyx in h5py._objects.with_phil.wrapper()
h5py\h5f.pyx in h5py.h5f.create()
OSError: Unable to create file (file exists)
During handling of the above exception, another exception occurred:
PermissionError Traceback (most recent call last)
<timed eval> in <module>
<ipython-input-19-1f1f9c5eb3dd> in vid_to_hdf(En, start, end, chunk)
10 f = h5py.File(filename, 'w-')
11 except:
---> 12 os.remove(filename)
13 f = h5py.File(filename, 'w-')
14 # Create dataset within file
PermissionError: [WinError 32] The process cannot access the file because it is being used by another process: 'E23.hdf5'