Can';使用`python.subprocess`对子进程进行t管道处理,以在Django`model.save()中调整图像大小并转换图像`

Can';使用`python.subprocess`对子进程进行t管道处理,以在Django`model.save()中调整图像大小并转换图像`,python,linux,django-models,subprocess,Python,Linux,Django Models,Subprocess,我想创建和修改网站的图像,图像可以创建在正确的位置现在如下代码,但我不能修改和格式化这些图像 class Bookmark(models.Model): title = models.CharField(max_length=200) user = models.ForeignKey(User) link = models.ForeignKey(Link) def __unicode__(self): return "%s, %s

我想创建和修改网站的图像,图像可以创建在正确的位置现在如下代码,但我不能修改和格式化这些图像

class Bookmark(models.Model):

    title = models.CharField(max_length=200)
    user = models.ForeignKey(User)       
    link = models.ForeignKey(Link)

    def __unicode__(self):
        return "%s, %s" % (self.user, self.link.url)
    def save_image(self):
        import subprocess
        import os
        url = self.link.url.replace("http://","").replace("https://","")\
                  .replace("/","|")
        image_png = './teststatic/url_image/' + url + ".png"
        image_jpg = './teststatic/url_image/' + url + ".jpg"
        command_line = "python", "webkit2png.py","-o", image_png, self.link.url
        image_crop = "mogrify", "-crop", "1280x1024+0+0", image_png
        image_convert = "mogrify", "-format", "jpg", image_png 
        image_del = "rm", image_png
        image_resize = "mogrify", "-resize", "150", "-quality", "80", image_jpg
        p1=subprocess.Popen(command_line, stdout=subprocess.PIPE)
        p2=subprocess.Popen(image_crop, stdin=p1.stdout, stdout=subprocess.PIPE)
        p3=subprocess.Popen(image_convert, stdin=p2.stdout, stdout=subprocess.PIPE)
        p4=subprocess.Popen(image_del, stdin=p3.stdout, stdout=subprocess.PIPE)
        subprocess.Popen(image_resize, stdin=p4.stdout, stdout=subprocess.PIPE)
这里是错误跟踪(为了可读性而重新格式化):


管道有一些问题,如何解决?

第二个进程取决于第一个进程生成的文件。但是,当第二个进程启动时,第一个进程尚未完成,因此
png
image还不存在。改用
子流程.call()
等待()
方法:

p1=subprocess.Popen(command_line, stdout=subprocess.PIPE)
return_code = p1.wait()
if return_code > 0:
    raise Exception('First process failed!')

...

使用subprocess调用另一个python解释器几乎肯定是一种迹象,表明您对这个问题的思考是错误的。。。还有,你有什么理由可以;I don’我不能用PIL来调整大小吗?嗨,我只是引用了作者使用webkit2png.py和ImageMagick的一篇文章。这两种应用程序之间有很大区别吗?
p1=subprocess.Popen(command_line, stdout=subprocess.PIPE)
return_code = p1.wait()
if return_code > 0:
    raise Exception('First process failed!')

...