How To Set A Timeout Period For Downloading Youtube Video Audio Using Python And Windows
On some YouTube links youtube_dl takes hours to try to download them. So I want to set a time limit on how long it tries to download a video for. On MAC/Linux you can use Signal or
Solution 1:
I think you are looking for something similar like the following code part. It should work on Windows as well.
from subprocess import Popen, PIPE
from threading import Timer
def run(cmd, timeout_sec):
proc = Popen(cmd.split(), stdout=PIPE, stderr=PIPE)
timer = Timer(timeout_sec, proc.kill)
try:
timer.start()
stdout, stderr = proc.communicate()
finally:
timer.cancel()
run("sleep 1", 5)
run("sleep 5", 1)
Post a Comment for "How To Set A Timeout Period For Downloading Youtube Video Audio Using Python And Windows"