The code below seems to work reasonably well, but is this sort of
thing recommended/safe? Is there a better way?
I am running windows.
import time
import threading
class my_thread(threading.Thread):
def __init__(self, file):
self.file = file
threading.Thread.__init__(self)
def run(self):
self.file.write('<html><body>')
# test streamed html output
for i in range(10):
self.file.flush()
time.sleep(1) # simulate long-running process
# pad lines to be more than a chunk
self.file.write('<p>%100d </p>' % (i,))
self.file.write('</body></html>')
self.file.close()
def my_controller():
(rh, wh) = os.pipe()
r = os.fdopen(rh, 'r')
w = os.fdopen(wh, 'w')
response.headers['Content-Type'] = 'text/html'
my_thread(w).start()
return response.stream(r, 50) # set chunk size to something
small
Massimo