I have a function to convert a pdf file to a thumbnail after upload.
def book_post_save(sender, instance=False, **kwargs):
pdf = Post.objects.get(pk=instance.pk)
command = "convert -quality 95 -thumbnail 100 %s%s[0] %s%s" % (
settings.MEDIA_ROOT,
pdf.file,
settings.MEDIA_ROOT,
pdf.file
)
proc = subprocess.Popen(
command,
shell=True,
stdin=subprocess.PIPE,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
)
stdout_value = proc.communicate()[0]
post_save.connect(book_post_save, sender=Post)
But the subprocess command doesn't return anything. I tried to type it in a terminal but I got a subprocess-error-returned-non-zero-exit-status-1. I got no thumbnail generated.
proc.communicate()returns a tuple -(stdout, stderr). Your code, by having[0]aftercommunicate(), is throwing away stderr. I would suggest doing something likestdout_value, stderr_value = proc.communicate()instead which will allow you to look at the contents of stderr. - Shadow