I have a problem when I want to process an zip file included .SAFE file (Sentinel-1). In my script, in python, first I unzip the file, then I want to process the unzipped .SAFE file, and then delete the .SAFE file. But when I use a shutil.rmtree() function, I get an error like this:
“The process cannot access the file because it is being used by another process: ‘<path_to_safe_file>/<safe_file_name>.SAFE/measurement\s1a-ew-grd-hh-20150620t011253-20150620t011353-006450-00889e-001.tiff’”
To read and dispose a product I use this:
p = ProductIO.readProduct(safe_file_full_path)
For removing I use this:
Has someone some idea, why I can’t remove this? Or which file is using that file? I have also tried p.closeIO()… After using p.dipose() the p.getProductReader() is None. The problem is also when I do nothing product object. Just read and dispose.
Thanks for every idea
You are using Sentinel-1 data, right?
It might be that this is an issue in the product reader for Sentinel-1. Maybe some files are not correctly closed when the product is closed.
Product.dispose() calls Product.closeIO(). So it was a nice try of you, but it doesn’t help. Without looking into it, I fear you have no influence on this behaviour. The Java VM needs to be shutdown, only then the files are released.
Maybe, just maybe, you can use the
create_jvm(options) of jpy.
You can have a look at the __init__.py of snappy where these methods are used.
I move this to the s1tbx category, because the issue is more related to S1TBX and not to Python development.
Yes, it’s Sentinel-1 data.
Thanks for reply. I have tried using destroy_jvm(), but with not success, same error. Seems like to try some workaround solution
Did you ever come up with a good workaround? I’m having the same problem (but with Sentinel-3 data). Unzip the .tar files, and later want to delete the unzipped files. But when I try to delete the files using shutil.rmtree, I get the same error as you…