Displaying Output Onto Kid Template Instead Of Background

0 views
Skip to first unread message

hoboro

unread,
Mar 24, 2008, 4:51:06 PM3/24/08
to TurboGears
Everyone,

I am having a processes where I click on a button on a page and it
runs in the background. Is it possible
to bring this output so it can be viewed in a web browser instead of
viewing on the console?

I would like to have the user see his results getting processed.


Thank You
Rohan

Florent Aide

unread,
Mar 24, 2008, 5:06:27 PM3/24/08
to turbo...@googlegroups.com

You will need to read(chunksize) the stdout + stderr of your
background process and stream it down to the client in the same loop

for this you'll need to declare your url as streamed using this:

cherrypy.config.update({tg.url('url'): {'streamResponse': True}})

and then in the loop use a yield statement...

Sorry I don't have enough time for a real answer with code.

Florent.

Christopher Arndt

unread,
Mar 24, 2008, 5:09:45 PM3/24/08
to turbo...@googlegroups.com
hoboro schrieb:

Look at the standard library subprocess module. Capture the output of
the process you are running and attach it to a template variable.

The problem with this approach is that the page load will hang until
your background process has finished.

If this is not feasible, you could do this:

1) Run the background process in it's own thread an let it write it's
output to a file pipe or Queue.Queue.
2) Provide a controller method that reads from the pipe and returns all
data read within a certain timeout wrapped in a JSON response.
3) Build a JavaScript function in your page that regularly polls the
method from step 2) via AJAX and displays the returned data.

Chris

Florent Aide

unread,
Mar 24, 2008, 5:11:52 PM3/24/08
to turbo...@googlegroups.com

mix our two answers and you begin to get an idea :)

Reply all
Reply to author
Forward
0 new messages