[Web-SIG] WSGI and asyncronous applications support

Manlio Perillo manlio_perillo at libero.it
Tue Sep 18 16:44:46 CEST 2007


Jean-Paul Calderone ha scritto:
> On Tue, 18 Sep 2007 13:39:23 +0200, Manlio Perillo <manlio_perillo at libero.it> wrote:
>> [snip]
>>
>> 1) should be very simple to implement, and it is easy to understand how
>> to use it.
>>
>> As an example, we can use some API that calls a callback function when
>> the result is available:
>> conn.execute("SELECT * FROM test", query_callback)
>>
>> def query_callback(row):
>>    write(row[...])
>>
>>
>> 2) Can be implemented in mod_wsgi, however my problem is that I can't
>> figure out how the application can yield some data available after a
>> callback is called.
>>
> 
> I think you figured it out already, actually:
> 

Right.

>     def app(...):
>         conn.execute("SELECT * FROM test", query_callback)
>         # indicate not-done-yet, however
> 
>     def query_callback(...):
>         write(...)
>         conn.execute("SELECT * FROM test2", another_callback)
> 
>     def another_callback(...):
>         write(...)
>         finish()
> 
> If you can have one callback, then there's no reason you shouldn't be
> able to have an arbitrary number of callbacks.
> 

The problem is not with callbacks, but how the application can yield the 
data obtained via a callback


> Of course, this could also be expressed in a less error prone manner:
> 
 > [...]

I'm thinking about a different solution, using wsgi.pause_output:

def app(env):
    def cb():
       resume()

    # This send an asynchronous query request
    r = conn.execute("SELECT * FROM test", on_state_ready=cb)
    resume = env['wsgi.pause_output']()
    yield ''

    # Now you can read the data, as if the application is synchronous
    yield str(r.fetchall())



Not sure if this is possible, I'll try to do some tests with Twisted.



Thanks and regards  Manlio Perillo



More information about the Web-SIG mailing list