Skip to content

Instantly share code, notes, and snippets.

@kolotaev
Last active March 9, 2018 11:57
Show Gist options
  • Save kolotaev/6c03faecc062e8782ae082ad8c8e8599 to your computer and use it in GitHub Desktop.
Save kolotaev/6c03faecc062e8782ae082ad8c8e8599 to your computer and use it in GitHub Desktop.
wget that interrupts its execution and resumes back
#!/usr/bin/env python3
# usage: ./wget.py link-to-download [interrupt-timeout]
import subprocess
import sys
download_timeout = 60 * 3 # 3 minutes - default
if len(sys.argv) < 2:
print('Provide link to download')
exit(1)
if len(sys.argv) == 3:
download_timeout = 60 * int(sys.argv[2])
cmd = ['wget', '-c', sys.argv[1]]
while True:
try:
subprocess.run(cmd, timeout=download_timeout, check=True)
except subprocess.TimeoutExpired:
pass
except Exception as e:
print('Error %s' % e)
exit(1)
else:
break
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment