Re: improved async support in psycopg python2 branch

Daniele Varrazzo <[email protected]> Mon, 5 Apr 2010 19:39:10 +0100
Newsgroups gmane.comp.python.db.psycopg.devel
Message-ID <[email protected]>
On Mon, Apr 5, 2010 at 4:10 PM, Federico Di Gregorio <fog-NGVKUo/i/[email protected]> wrote:
> Hi *,
>
> I just merged and pushed almost all of Jan's changes into the official
> python2 branch of psycopg.

Hello fog, great news!

There is a couple of patches you can pull from my python2 branch.
Preview is at http://tinyurl.com/piro-psycopg2

in c486136d pgconn is put into conn as soon as is created and the
destructor is delegated to delete it. This not only simplifies a
little bit the error handling in connection creations, but is
necessary for the "green" branch because the python callback receives
a working (at least for fileno() and poll()) connection.

in c75ddea8 the async parameter is passed to the connection factory
only if it is nonzero, otherwise we break all the custom connection
factories that redefined __init__(dsn). At least now we break them
only in async mode (we can document then that the connection signature
is currently __init__(dsn, async=0) )

> next release won't break anything but I'd like to have as many people as
> possible test the current release candidate tarball:
>
> http://initd.org/pub/software/psycopg/psycopg2-2.2.0rc1.tar.gz
> http://initd.org/pub/software/psycopg/psycopg2-2.2.0rc1.tar.gz.asc

Will the "green" branch make for this release? It is now mostly
finished (available in the green2 branch of my repos): now that Jan
patches are in the main repos I can integrate my branch.

There are a few things I've noticed working with the libpq async
functions (not limited to the async nor the green branches):
PQsetnonblocking(1) is called also for sync connections, but I am not
sure that all the libpq calls can deal with "would block" error.
_pq_copy_in[_v3] are two of them (the libpq v2 async copy si probably
hopelessly broken, for what i've read from 2002 emails): may this be
causing the problems in COPY FROM i've read about? (I coluldn't
reproduce them) It probably worth a review of the functions that would
block.

-- Daniele