Hello group! I want to mimic the behavior of console application through web interface: I invoke a process in web2py controller function and try to pipe its stdout to user's browser (no keyboard input is needed). These are time-consuming processes that print out their progress with simple python print command. I wanted the user to see these printed messages in browser window, gradually as they are printed by a process.
Here is a controller function: ************************************************************************* import subprocess def score(): cmd=['ls', '-la'] proc = subprocess.Popen(cmd, stdout=subprocess.PIPE, \ stderr=subprocess.STDOUT) response.headers['Content-Type'] = 'text/plain' response.headers['Content-Length'] = 10**6 return response.stream(proc.stdout, 16) ************************************************************************** Imagine that instead of 'ls -la' we run a process that does something like: ************************************************************************** for i in range (10000): sleep(1000) print i ************************************************************************* With this setup I achieved the following: when process ends, the whole stdout contents is passed to the browser and displayed. But there is no effect of gradual streaming of printouts to the browser. If you notice the value 16 in stream command in controller, it's buffer size. From other experiments with streaming in web2py I managed to stream very large CSV files output to browser (download) during the time of their generating; if I make buffering chunks less than initial portion of data, it streams. Otherwise it waits until the whole file is ready and then sends it to browser. subprocess.PIPE is file-like object provided by subprocess module. But here in subprocess STROUT streaming, this playing with buffer size does not help. Any ideas? --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "web2py Web Framework" group. To post to this group, send email to web2py@googlegroups.com To unsubscribe from this group, send email to web2py+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/web2py?hl=en -~----------~----~----~----~------~----~------~--~---