I do not seem an immediate problem except the fact that a thread started by the web server starts another thread and it may get killed for long running tasks. I suggest you look into the admin/controller/ shell.py
Massimo On Apr 14, 8:23 pm, Paul Wray <paul.w...@det.nsw.edu.au> wrote: > Hello > I would like to make some administative build/test tasks for a web2py > application available via the web interface, with the output presented > to the html page in real time, like console output. > > 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 -- To unsubscribe, reply using "remove me" as the subject.