[Image-SIG] Broken Pipe

Lionel Roubeyrie lroubeyrie at limair.asso.fr
Thu Jan 27 16:08:54 CET 2005


Hi again,
after debugging time, ghostscript doesn't like to be invoked with the "- 
>/dev/tty 2>/dev/tty" option in mod_python with apache, because mod_python 
doesn't open a real tty. Then "gs.write(s)" crashes with a broken pipe. 
I have modified the Ghostscript method to revoke this :
##################################
def Ghostscript(tile, size, fp):
    """Render an image using Ghostscript (Unix only)"""

    # Unpack decoder tile
    decoder, tile, offset, data = tile[0]
    length, bbox = data

    import tempfile, os

    outfile = tempfile.mktemp()
    infile = tempfile.mktemp()

    # Build ghostscript command
    command = ["gs",
               "-q",                    # quite mode
               "-g%dx%d" % size,        # set output geometry (pixels)
               "-dNOPAUSE -dSAFER -dBATCH",     # don't pause between pages, 
safe mode
               "-sDEVICE=ppmraw",       # ppm driver
               "-sOutputFile=%s" % outfile,# output outfile
               infile]

    command = string.join(command)

    # push data through ghostscript
    try:
        ps = open(infile, 'w')
        # adjust for image origin
        if bbox[0] != 0 or bbox[1] != 0:
            ps.write("%d %d translate\n" % (-bbox[0], -bbox[1]))
        fp.seek(offset)
        while length > 0:
            s = fp.read(8192)
            if not s:
                break
            length = length - len(s)
            ps.write(s)
        ps.close()
        os.popen(command)
        im = Image.core.open_ppm(outfile)
    finally:
        try: 
            os.unlink(outfile)
            os.unlink(infile)
        except: pass

    return im

################################
Now it works well.
Hope it helps (Zopemen seem to have the same problem ...)

Lionel, aka Joshua_fr



More information about the Image-SIG mailing list