Re: Async branch documentation and review

Jan Urbański <[email protected]> Sat, 10 Apr 2010 19:08:13 +0200
Newsgroups gmane.comp.python.db.psycopg.devel
Message-ID <[email protected]>
On 10/04/10 18:30, Jan Urbański wrote:
> On 10/04/10 17:32, Daniele Varrazzo wrote:
>>>> [async review]

> I'll add a CONN_STATUS_SETUP status and returning PSYCO_POLL_WRITE in
> that state with async connections and that will allow to use the same
> loop for connecting and executing. Thanks for pointing that out.

OK, I made connection.poll() return POLL_WRITE the first time it's run, 
disallowed polling a different cursor that the one executing an async 
query and made connection.executing() return True also when there is an 
async connection attempt underway. The changes are in

http://git.wulczer.org/?p=psycopg2.git;a=shortlog;h=refs/heads/async_fixes

This allowed to have a uniform loop for both connections and cursors, 
just like you proposed:

def wait(self, pollable):
     while True:
         state = pollable.poll()
         if state == psycopg2.extensions.POLL_OK:
             break
         elif state == psycopg2.extensions.POLL_READ:
             select.select([pollable], [], [])
         elif state == psycopg2.extensions.POLL_WRITE:
             select.select([], [pollable], [])
         else:
             raise Exception("Unexpected result from poll: %r", state)

Where "pollable" is something with a pollable interface, i.e. something 
that has a poll() and a fileno() method. The test_async.py tests have 
been updated to use that method of waiting for both connections and 
cursors and it works.

As for fetching from a wrong cursor after an async execution has ended, 
it seems to behave sanely. Fetching *while* there is an async execution 
raises an exception (see test_fetch_after_async), fetching with the 
wrong cursor after the async execution completed raises a "no results to 
fetch" error (see test_async_fetch_wrong_cursor), just like fetching 
from a newly created sync cursor before executing anything with it.

Thanks for all your suggestions!

Cheers,
Jan
_______________________________________________
Psycopg mailing list
[email protected]
http://lists.initd.org/mailman/listinfo/psycopg