Last active
November 28, 2019 00:47
-
-
Save huxuan/d58a5899be9b42e0936c71dd7884442a to your computer and use it in GitHub Desktop.
Subprocess failed to kill child process when using with statement.
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
from urllib.request import urlopen | |
import subprocess | |
import time | |
url = 'https://iptv-org.github.io/iptv/index.m3u' | |
with urlopen(url) as response: | |
for line in response.read().decode('utf-8').splitlines(): | |
if line.startswith('http'): | |
start_time = time.time() | |
# with statement, does not work | |
with subprocess.Popen(f'ffprobe -v quiet {line}'.split(), stdout=subprocess.PIPE) as proc: | |
try: | |
outs, errs = proc.communicate(timeout=.1) | |
except subprocess.TimeoutExpired: | |
proc.kill() | |
# # NO with statement, work | |
# proc = subprocess.Popen(f'ffprobe -v quiet {line}'.split(), stdout=subprocess.PIPE) | |
# try: | |
# outs, errs = proc.communicate(timeout=.1) | |
# except subprocess.TimeoutExpired: | |
# proc.kill() | |
print(f'{time.time() - start_time}') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment