aboutsummaryrefslogtreecommitdiff
path: root/youtube_dl/downloader/external.py
diff options
context:
space:
mode:
authorpukkandan <pukkandan@gmail.com>2021-01-09 17:56:12 +0530
committerdirkf <fieldhouse@gmx.net>2022-06-10 19:57:46 +0100
commit0700fde6403aa9eec1ff02bff7323696a205900c (patch)
treef1ed405d2af1934a06ff2091420172a0cc98f23a /youtube_dl/downloader/external.py
parent811c480f7b6c25ca510a033e6365d00174135392 (diff)
downloadyoutube-dl-0700fde6403aa9eec1ff02bff7323696a205900c.tar.xz
[utils, etc] Kill child processes when yt-dl is killed
* derived from PR #26592, closes #26592 Authored by: Unrud
Diffstat (limited to 'youtube_dl/downloader/external.py')
-rw-r--r--youtube_dl/downloader/external.py16
1 files changed, 10 insertions, 6 deletions
diff --git a/youtube_dl/downloader/external.py b/youtube_dl/downloader/external.py
index c31f8910a..a06ab2e50 100644
--- a/youtube_dl/downloader/external.py
+++ b/youtube_dl/downloader/external.py
@@ -22,6 +22,7 @@ from ..utils import (
handle_youtubedl_headers,
check_executable,
is_outdated_version,
+ process_communicate_or_kill,
)
@@ -104,7 +105,7 @@ class ExternalFD(FileDownloader):
p = subprocess.Popen(
cmd, stderr=subprocess.PIPE)
- _, stderr = p.communicate()
+ _, stderr = process_communicate_or_kill(p)
if p.returncode != 0:
self.to_stderr(stderr.decode('utf-8', 'replace'))
return p.returncode
@@ -141,7 +142,7 @@ class CurlFD(ExternalFD):
# curl writes the progress to stderr so don't capture it.
p = subprocess.Popen(cmd)
- p.communicate()
+ process_communicate_or_kill(p)
return p.returncode
@@ -336,14 +337,17 @@ class FFmpegFD(ExternalFD):
proc = subprocess.Popen(args, stdin=subprocess.PIPE, env=env)
try:
retval = proc.wait()
- except KeyboardInterrupt:
- # subprocces.run would send the SIGKILL signal to ffmpeg and the
+ except BaseException as e:
+ # subprocess.run would send the SIGKILL signal to ffmpeg and the
# mp4 file couldn't be played, but if we ask ffmpeg to quit it
# produces a file that is playable (this is mostly useful for live
# streams). Note that Windows is not affected and produces playable
# files (see https://github.com/ytdl-org/youtube-dl/issues/8300).
- if sys.platform != 'win32':
- proc.communicate(b'q')
+ if isinstance(e, KeyboardInterrupt) and sys.platform != 'win32':
+ process_communicate_or_kill(proc, b'q')
+ else:
+ proc.kill()
+ proc.wait()
raise
return retval