I am making a RPM file cache server. A PC on the network accesses the cache server. If the file is present on the server, it is served. If not, it is downloaded from the internet before being served.
I wrote this with BaseHTTPServer with urllib to fetch the files. Now with small files, there is little delay between downloading the file and serving it.
...
store_file.write(download_buffer.read())
store_file.close()
...
f=open(file_path,'r')
self.wfile.write(f.read())
...
But some files may take minutes to download. So the client is kept waiting, while server finishes the file. This may cause client to time-out. How do we serve the file as it is being downloaded to prevent time-outs by the client?
A read-write loop.