5
# conn can be a connection or a cursor
6
if not hasattr(conn, 'poll'):
9
# interesting part: suspend until ready
12
if state == psycopg2.extensions.POLL_OK:
14
elif state == psycopg2.extensions.POLL_READ:
15
uwsgi.green_wait_fdread(conn.fileno())
16
elif state == psycopg2.extensions.POLL_WRITE:
17
uwsgi.green_wait_fdwrite(conn.fileno())
19
raise Exception("Unexpected result from poll: %r", state)
25
def application(env, start_response):
27
start_response('200 Ok', [('Content-type', 'text/html')])
29
conn = psycopg2.connect("dbname=prova user=postgres", async=True)
31
# suspend until connection
38
curs.execute("SELECT * FROM tests")
40
# suspend until result
46
yield "<tr><td>%s</td></tr>" % str(row)