[mod_python] O/S SendFile call

Conrad Steenberg conrad at hep.caltech.edu
Fri Feb 6 04:54:47 EST 2004


Hi Oliver

The request class in newer versions (3.1b2+ I think) has a write_file
method that you can use as follows:

# First init the offset and bytes variables, then:
  try:
    while bytes>0:
      sent=0
      sent=req.write_file(filename,offset,bytes)
      if sent<0: raise OSError(5,"Error sending file")
      offset=offset+sent
      bytes=bytes-sent
  except:
    # handle error
    pass
  return apache.OK

HTH

Conrad

On Wed, 2004-02-04 at 22:16, Oliver Nelson wrote:
> I read in the apache docs that if possible you should try and have an O/S version that has the sendfile call so that apache doesn't have to do a read and a send of files.
> 
> I am writing a python handler that has to go out on a network, find a file and then pass then return that file to the client browser.  Right now I'm reading in the file and then writing it the output stream.  It seems that there should be a much better way to do this like apache does it with sendfile.  Is it possible to use this (the sendfile os call) from inside my python handler?
> 
> OLIVER
> _______________________________________________
> Mod_python mailing list
> Mod_python at modpython.org
> http://mailman.modpython.org/mailman/listinfo/mod_python
-- 
Conrad Steenberg <conrad at hep.caltech.edu>
-- 
Conrad Steenberg <conrad at hep.caltech.edu>


More information about the Mod_python mailing list