Re: Emulating req.write() in WSGI

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Re: Emulating req.write() in WSGI

Gustavo Narea
http://pythonpaste.org/waitforit/

HTH.

 - Gustavo.

Aaron said:

> One of the nice things about mod_python is the req.write() function.
>
> Although I realize it's somewhat of an abuse to the http protocol, it's
> handy being able to periodically update the client browser with a status
> message for a long-running job.
>
> So handy in fact that I have a number of applications that rely fairly
> heavily on it as a means of keeping the client (person) happy instead of
> just showing them the default "browser busy" notification.
>
> There are a couple of workarounds, neither of which are ideal:
> 1. Take them immediately to a secondary page, then submit the actual job
> automatically on that second page.
> 2. Instead of using HTTP POST, use an HTTP Request Object (ie. Ajax).
>
> Both of them involve significantly more development effort than an
> equivalent req.write().
>
> Is there a way to emulate the periodic-write functionality in WSGI?
--
Gustavo Narea <xri://=Gustavo>.
| Tech blog: =Gustavo/(+blog)/tech  ~  About me: =Gustavo/about |
_______________________________________________
Web-SIG mailing list
[hidden email]
Web SIG: http://www.python.org/sigs/web-sig
Unsubscribe: http://mail.python.org/mailman/options/web-sig/lists%40nabble.com
Reply | Threaded
Open this post in threaded view
|

Re: Emulating req.write() in WSGI

ianb
On Mon, Jun 28, 2010 at 2:50 PM, Gustavo Narea <[hidden email]> wrote:
http://pythonpaste.org/waitforit/

It will address this problem, but not with mod_wsgi as it relies on threads to handle the queuing (the request is deferred to a thread, and in-memory data structures are used to get the result).

One of the solutions proposed ("Take them immediately to a secondary page, then submit the actual job automatically on that second page.") actually seems most reasonable to me, as it allows you to give any UI you want (where writing out a response incrementally is fairly constrained), and can be generalized fairly easily.  And if you use a little persistence (something WaitForIt doesn't have the benefit of using) you could fire off XMLHttpRequests to get an update.  Hmm... WaitForIt would almost be better simply doing this, except it tries to be clever by avoiding interstitial pages if the response isn't slow.

And then there's really cheap tricks, like:

<button type="submit" onclick="this.innerHTML = 'submitting...'; this.disabled = true">Submit</button>

--
Ian Bicking  |  http://blog.ianbicking.org

_______________________________________________
Web-SIG mailing list
[hidden email]
Web SIG: http://www.python.org/sigs/web-sig
Unsubscribe: http://mail.python.org/mailman/options/web-sig/lists%40nabble.com