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

Christopher Markiewicz markiewicz at stanford.edu
Fri Jan 14 11:10:18 EST 2022


Hi Eric,

You may want to use `mmap=False` when loading to ensure that the data array is loaded into RAM rather than memory mapped. Apart from that, the file handles shouldn't be left open.

Best,
Chris

________________________________________
From: Neuroimaging <neuroimaging-bounces+markiewicz=stanford.edu at python.org> on behalf of Eric Condamine <eric.condamine at univ-grenoble-alpes.fr>
Sent: Friday, January 14, 2022 10:27
To: neuroimaging at python.org
Subject: [Neuroimaging] The process cannot access the file because it is being used by another process ...

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-2016-03-17083444-00<callto: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-2016-03-17083444-00<callto: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-2016-03-17083444-00<callto: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




More information about the Neuroimaging mailing list