I am reading images (through Python) and do something. These images are placed in a temporary file, through:

tf = tempfile.mkdtemp(filename)

I use gdal to read the images (short part of code):

tif_image = gdal.Open(str(out_ROI))
x = tif_image.RasterXSize
y = tif_image.RasterYSize
geo = tif_image.GetGeoTransform()
band = tif_image.GetRasterBand(1)
Values = band.ReadAsArray(0,0,x,y)

In the end I want to delete the folder created with mkdtemp, through:

import shutil

Before that I close the images just as I read in this posts:

band = None
Values = None
tif_image = None 

But I always get the error:

WindowsError: [Error 32] The process cannot access the file because it is being used by another process

What I am missing?

  • Any solution so far ? I'm in the same place Sep 5 '19 at 11:53

Maybe you are trying to remove the folder which is your current system path? I mean, it could be that you are trying to remove a folder when the system is in that folder. Try os.getcwd() to see if so. If it's you'd only need to change the system path (os.chdir()).


You are clearing the variable, you are not closing the file. To close the file, you need to have:


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.