Async support refactoring

Daniele Varrazzo <[email protected]> Fri, 23 Apr 2010 16:14:06 +0100
Newsgroups gmane.comp.python.db.psycopg.devel
Message-ID <[email protected]>
Hello,

I have merged Jan's support to async connections with the green
branch: the result is probably the best async support among the Python
database drivers. Here is a quick review of what I've done for use to
everybody dealing with psycopg source code.

Here <http://tinyurl.com/26zghdo> it is possible to see a few stacked
tags: what goes up to "async-rebased" is the straightened out version
of the interwoven trees in which Jan and me have worked on the async
support in the last weeks as discussed on the mailing list. On top of
it I rebased the "green branch" I've already talked about and in which
I have worked while the async support was finished.

After the merge (tag "green-rebased") there was a lot of duplicate
code, dealing with the many things that poll() should do according to
the connection type, current state etc. I refactored everything in
order to have a single poll() implementation and to put the common
polling patterns (poll after a connection, poll after a query...) in
separate functions. What you will find now (in connection_int.c) is a
single conn_poll() checking the conn->status member and calling some
of the functions '_conn_poll_*()', which are in charge of performing
the different actions and moving the connection state. A lot of code
has been simplified, for instance now the async setup uses the same
polling code used by the regular database queries, and the state
changes have been largely simplified.

The result is available at the tag "green-async-merged", which is
awaiting for review and upstream integration.

From this point it should be straightforward to add async COPY
support: we will need a few new states to be handled in conn_poll()
and a couple of functions to call the proper libpq function. I don't
have an immediate interest in this implementation, so for me it can be
postponed after the 2.2 release.

Any feedback is appreciated. Regards.

-- Daniele