On Tue, 18 Sep 2007 13:39:23 +0200, Manlio Perillo
<manlio_perillo 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:
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.
Of course, this could also be expressed in a less error
prone manner:
def app(...):
test_deferred = conn.execute("SELECT * FROM
test")
test_deferred.addCallback(query_callback)
return test_deferred
def query_callback(...):
write(...)
test2_deferred = conn.execute("SELECT * FROM
test2")
test2_deferred.addCallback(another_callback)
return test2_deferred
def another_callback(...):
write(...)
;)
Jean-Paul
_______________________________________________
Web-SIG mailing list
Web-SIG python.org
Web SIG: http://www.python.
org/sigs/web-sig
Unsubscribe: http://mail.python.org/mailman/options/web-sig/bo
nd%40yahoo.com
|