def make_pdf_thumbnail2(path, width):
    width_str = str(width)
    dir, name = os.path.split(path)
    base, ext = os.path.splitext(name)
    newbase = "%s_thumb%s" % (base, width_str)
    dst = os.path.join(dir, newbase + THUMB_EXT)

    def page(n):
        """Return the filename for page n's thumbnail, n >= 0.
           'n' may also be a string (e.g., "*" for wildcard patterns).
           If 'n' is None, return value has no page suffix.
        """
        if n is not None:
            suffix = "-%s" % n
        else:
            suffix = ""
        return os.path.join(dir, newbase + suffix + THUMB_EXT)

    trashcan = open("/dev/null", "w")
    
    ## A few settable options
    if THUMB_EXT == ".jpg":
        filetype = "jpeg" # jpeg
    elif THUM_EXT == ".png":
        filetype = "png16m" # 24 bit png
    else:
        filetype = "jpeg" # should this be default
    
    gs_path = "/usr/local/bin/gs"
    ps_cmd = "save pop currentglobal true setglobal false/product where{pop product(Ghostscript)search{pop pop pop revision 600 ge{pop true}if}{pop}ifelse}if{/pdfdict where{pop pdfdict begin/pdfshowpage_setpage[pdfdict/pdfshowpage_setpage get{dup type/nametype eq{dup/OutputFile eq{pop/AntiRotationHack}{dup/MediaBox eq revision 650 ge and{/THB.CropHack{1 index/CropBox pget{2 index exch/MediaBox exch put}if}def/THB.CropHack cvx}if}ifelse}if}forall]cvx def end}if}if setglobal"
    cmd = [gs_path, "-dSAFER","-dBATCH","-dNOPAUSE","-dLastPage=1","-dTextAlphaBits=4"]
    cmd.append("-sDEVICE=%s"%filetype)
    #dpi  = int(width / 8.5) ## this assumes an 8.5in wide piece of paper.
    dpi = 20
    cmd.append("-r%i"%dpi)
    
    cmd.append("-sOutputFile=%s"% dst)
    cmd.extend(("-c", ps_cmd, "-f"),)
    cmd.append(path)
    
    ## the desired command string
    ## gs -dSAFER -dBATCH -dNOPAUSE -r150 -sDEVICE=jpeg -dTextAlphaBits=4 -sOutputFile=$1-%02d.jpg $1
    status = subprocess.call(cmd, shell=False) #, stdout=trashcan, stderr=trashcan)
    if status:
        warn("make_pdf_thumbnail subcommand exited with status %s: %s", 
            status, cmd)
    trashcan.close()
    found = False
    if os.path.exists(dst):
        return dst
    else:
        return None
Read until EOF, using multiple read() call.
dataset/ETHPy150Open mikeorr/WebHelpers2/unfinished/multimedia.py/make_pdf_thumbnail2--crossover with--dataset/ETHPy150Open azoft-dev-team/imagrium/env/Lib/_pyio.py/RawIOBase.readall