我有一个运行在我的web服务器上的python脚本。主函数被调用,然后当它返回它只是睡几秒钟,再次被调用。目的是获取用户添加的所有新上传的视频并将其转换为webm,将中间框架作为图像和其他一些时髦的东西拉出。我正在使用ffmpeg的外部调用。下面的代码片段显示了我如何称它。如何检查状态或使用python杀死外部进程
duration = output[durationIndex+10:durationIndex+18]
durationBits = duration.split(":")
lengthInSeconds = (int(durationBits[0])*60*60) + (int(durationBits[1])*60) + (int(durationBits[2]))
child = subprocess.Popen(["ffmpeg","-y","-i",sourceVideo,"-f","mjpeg","-vframes","1","-ss",str(lengthInSeconds/2),destination], shell=True, stderr=subprocess.PIPE)
output = ""
while True:
out = child.stderr.read(1)
if out == '' and child.poll() != None:
break
if out != '':
output += out
updateSQL = "update `videos_graduatevideo` set thumbnail = '" + str(destination) + "' where `original_video` = '" + sourceVideo + "'"
cursor.execute(updateSQL)
此脚本运行在Windows机器atm上,但我可能会在开发完成时将它部署到Unix系统上。
问题是。我需要这个python脚本来继续运行。如果ffmpeg出现问题并且我的脚本挂起,用户上传的视频就会处于“挂起”状态,直到我去戳python脚本。我知道一个特定的mov文件让ffmpeg不能完全挂起。有没有办法可以检查一个进程已经运行了多长时间,如果运行时间过长,就把它关闭?
我有完全相同的问题(我使用的是Pylons而不是Django)。我编写了一个具有数据库访问权限的外部程序(如果你给它Django的设置,你可以使用你的模型)和ajax轮询系统来获得结果。 – JBernardo 2011-12-29 19:21:36
[芹菜](http://celeryproject.org/)怎么样?有[监测](http://celery.readthedocs.org/en/latest/userguide/monitoring.html)支持。 – danihp 2011-12-30 22:13:44