From cb315a7a8603fcb39e5371bcafc305fedc7ef398 Mon Sep 17 00:00:00 2001 From: j <0x006A@0x2620.org> Date: Fri, 27 Jun 2008 18:08:16 +0200 Subject: [PATCH] port run_command from pad.ma, kill subproces if they do not finish in time --- oxdbarchive/extract.py | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/oxdbarchive/extract.py b/oxdbarchive/extract.py index 98a26e7..fd8c895 100644 --- a/oxdbarchive/extract.py +++ b/oxdbarchive/extract.py @@ -11,6 +11,18 @@ from subtitles import time2ms img_extension="jpg" +def run_command(cmd, timeout=25): + p = subprocess.Popen(cmd, shell=True) + while timeout > 0: + time.sleep(0.2) + timeout -= 0.2 + if p.poll() != None: + return p.returncode + if p.poll() == None: + os.kill(p.pid, 9) + killedpid, stat = os.waitpid(p.pid, os.WNOHANG) + return p.returncode + def extract_flash_ng(movie_file, flash_file, inpoint, outpoint, width=128, height=96, offset = 0): ext = movie_file.split('.')[-1] if ext in ('sub', 'srt'): @@ -157,10 +169,11 @@ def extract_poster_still(movie_file, png_file, inpoint): extractClipScript = abspath(join(dirname(__file__), "tools/extract_frame.py")) cmd = '''%s "%s" "%s" %s 0 128''' % (extractClipScript, movie_file, png_file, inpoint) - os.system(cmd.encode('utf-8')) + run_command(cmd.encode('utf-8')) def extract_subtitles(movie_file, srt, img_folder, width=128, offset = 0, redo = False): subtitles = srt2dict(srt) for k in sorted([int(k) for k in subtitles]): timestamp = subtitles["%s" % k]['start'] extract_frame(movie_file, timestamp, img_folder, width, offset, redo) +