I'm processing a file and then want to remove it. My code ends with:
...
tar.extractall(dir=...)
tar.close()
os.remove(filename)
This sometimes causes an error:
[Errno 16] Resource busy: 'skyimage/sgptsiskyimageC1.a1.20160415.000000.jpg.tar'
I was able to work around this by telling Python to keep trying until it works:
while True:
try:
os.remove(filename)
break
except OSError as err:
continue
Is there a more Pythonic way to do this?