[Neuroimaging] The process cannot access the file because it is being used by another process ...

Eric Condamine eric.condamine at univ-grenoble-alpes.fr
Fri Jan 14 10:27:08 EST 2022


Dear all, 

I observe a small issue with nibabel only under Windows which unlike macos or linux does not allow to delete a file used by a process. 
Minimum procedure to reproduce: 

PS C:\Users\econd> python 
Python 3.9.7 (tags/v3.9.7:1016ef3, Aug 30 2021, 20:19:38) [MSC v.1929 64 bit (AMD64)] on win32 
Type "help", "copyright", "credits" or "license" for more information. 
>>> import nibabel as nib 
>>> import os, sys 
>>> b=nib.as_closest_canonical(nib.load('C:\\Users\\econd\\Desktop\\test\\alej170316-IRMFonct_+perfusion- [ callto:2016-03-17083444-00 | 2016-03-17083444-00 ] -T13DSENSE-T1TFE-000425_000.nii')) 
>>> b<nibabel.nifti1.Nifti1Image object at 0x000001D898202580 
>>>> os.remove('C:\\Users\\econd\\Desktop\\test\\alej170316-IRMFonct_+perfusion- [ callto:2016-03-17083444-00 | 2016-03-17083444-00 ] -T13DSENSE-T1TFE-000425_000.nii') 
Traceback (most recent call last): File "<stdin>", line 1, in <module>PermissionError: [WinError 32] The process cannot access the file because it is being used by another process: 'C:\\Users\\econd\\Desktop\\test\\alej170316-IRMFonct_+perfusion- [ callto:2016-03-17083444-00 | 2016-03-17083444-00 ] -T13DSENSE-T1TFE-000425_000.nii' 

Without going into details in order to not make you waste time unnecessarily, we need in some codes to have access to the b object (vide supra) and then in some cases to delete the file used in the instanciation of b. Under macos and linux no problem but under windows we have the PermissionError exception. How can we manage to delete the file? (del b is not enough!). 

All the best for 2022! 
Eric 


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mail.python.org/pipermail/neuroimaging/attachments/20220114/98529e22/attachment.html>


More information about the Neuroimaging mailing list