nyc-stabilization-unit-counts
nyc-stabilization-unit-counts copied to clipboard
download_direct.py is sometimes failing to delete files
I am running download_direct.py in an AWS instance, with the data directory as a symlink to an S3 bucket mounted using S3FS. Occasionally this line causes a fail:
return subprocess.check_call(
'wget --no-check-certificate --max-redirect=0 -O "{filename}" "{url}" '
' || (rm "{filename}" && touch "{nofilemarker}")'.format(
filename=filename,
url=url,
nofilemarker=os.path.join(bbldir, nostatement_fname)
), shell=True)
Because the "rm" portion returns an error status from the shell prompt, indicating that the file attempting to be deleted cannot be found. I was able to fix this using:
return subprocess.check_call(
'wget --no-check-certificate --max-redirect=0 -O "{filename}" "{url}" '
' || (rm -f "{filename}" && touch "{nofilemarker}")'.format(
filename=filename,
url=url,
nofilemarker=os.path.join(bbldir, nostatement_fname)
), shell=True)
By adding the "-f" switch to rm, it suppresses the "i tried to delete a file which isn't there" error. You may or may not want to include this in the actual master, as this may be an artifact of S3FS, but it was driving me nuts because download_direct kept dying in the middle.