Last active
May 9, 2021 13:09
-
-
Save linw1995/c32d3757a5abef867037ab88b3072274 to your computer and use it in GitHub Desktop.
Simple script for executing command with retry
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import os | |
import subprocess | |
import sys | |
def run_cmd_with_retry( | |
cmd, | |
retry_count_limit=3, | |
retry_delay_seconds=60, | |
stdout=sys.stdout.fileno(), | |
stderr=sys.stderr.fileno(), | |
): | |
for retry_count in range(retry_count_limit): | |
if retry_count > 0: | |
os.write(stdout, f"run {cmd} with {retry_count = !r}\n".encode()) | |
else: | |
os.write(stdout, f"run {cmd}\n".encode()) | |
try: | |
subprocess.check_call(cmd, stdout=stdout, stderr=stderr) | |
break | |
except subprocess.CalledProcessError: | |
pass | |
else: | |
os.write(stdout, f"run {cmd} error\n".encode()) | |
def main(): | |
urls = [] | |
for url in sorted(set(urls)): | |
run_cmd_with_retry(cmd=["youtube-dl", "-R", "infinite", "-c", "--recode-video", "mp4", url]) | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment