使用呼叫它处理视频转换(内部使得curl命令向媒体服务器),应立即返回到用户的功能。Python的线程没有返回值
使用消息队列会对应用程序造成过大的影响。 所以我决定使用线程,我写这将覆盖init和run方法,并调用curl命令
class process_video(Thread):
def __init__ (self,video_id,video_title,fileURI):
Thread.__init__(self)
self.video_id = video_id
self.video_title = video_title
self.fileURI = fileURI
self.status =-1
def run(self):
logging.debug("FileURi" + self.fileURI)
curlCmd = "curl --data-urlencode \"fileURI=%s\" %s/finalize"% (self.fileURI, settings.MEDIA_ROOT)
logging.debug("Command to be executed" + str(curlCmd))
#p = subprocess.call(str(curlCmd), shell=True)
output_media_server,error = subprocess.Popen(curlCmd,stdout = subprocess.PIPE).communicate()
logging.debug("value returned from media server:")
logging.debug(output_media_server)
一类,我从名为createVideo 另一个函数调用这样success = process_video(video_id, video_title, fileURI)
问题: 用户从createVideo重定向回到另一个视图,processVideo被调用,但由于某种原因,创建的线程(process_video)不会等待来自媒体服务器的输出。
我需要一些更多的信息在这里。使用'process_video'的代码是什么样的?我假设你做的不仅仅是创建'process_video'的实例。 – Arlaharen 2010-11-22 06:52:40
添加'stderr = PIPE'并记录'error'。 – jfs 2010-11-22 07:47:59
subprocess.Popen调用似乎卡住了,因为它似乎没有记录任何错误或输出。我也检查了媒体服务器日志,并且没有对它进行调用。将process_video的实例设置为守护进程也无济于事。有任何想法吗? – 2010-11-22 14:20:06