diff options
author | pukkandan <pukkandan@gmail.com> | 2021-01-09 17:56:12 +0530 |
---|---|---|
committer | pukkandan <pukkandan@gmail.com> | 2021-01-09 18:08:07 +0530 |
commit | f5b1bca9139fcbac76dca3a6b17e69f53a885988 (patch) | |
tree | 2426a3eef3733d998bdcd0ac3d56a42f155ce7d7 /youtube_dlc/downloader/external.py | |
parent | d9eebbc7471b97f3aa58939685bd7b8f4ce35b1e (diff) | |
download | hypervideo-pre-f5b1bca9139fcbac76dca3a6b17e69f53a885988.tar.lz hypervideo-pre-f5b1bca9139fcbac76dca3a6b17e69f53a885988.tar.xz hypervideo-pre-f5b1bca9139fcbac76dca3a6b17e69f53a885988.zip |
Kill child processes when yt-dlc is killed (https://github.com/ytdl-org/youtube-dl/pull/26592)
Authored by: Unrud
Diffstat (limited to 'youtube_dlc/downloader/external.py')
-rw-r--r-- | youtube_dlc/downloader/external.py | 14 |
1 files changed, 9 insertions, 5 deletions
diff --git a/youtube_dlc/downloader/external.py b/youtube_dlc/downloader/external.py index d2f8f271d..8cd0511fc 100644 --- a/youtube_dlc/downloader/external.py +++ b/youtube_dlc/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 @@ -143,7 +144,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 @@ -343,14 +344,17 @@ class FFmpegFD(ExternalFD): proc = subprocess.Popen(args, stdin=subprocess.PIPE, env=env) try: retval = proc.wait() - except KeyboardInterrupt: + except BaseException as e: # subprocces.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 |