Re: In re: improving async support in psycopg

Alexander Sabourenkov <[email protected]> Fri, 09 Apr 2010 16:07:59 +0400
Newsgroups gmane.comp.python.db.psycopg.devel
Message-ID <[email protected]>
Hello.

> your library is really interesting, I didn't know it. I'd appreciate
> if you could think about how to integrate coev with the "green"
> psycopg branch.
>
> Other libraries have a Python roundtrip every time a libpq call
> blocks. It seems your library wouldn't need that, but currently I am
> only expecting a Python callback to register the wait function.

Well, not having Python roundtrips every time something blocks was the 
whole point of it. So in psycoev, control passes Python/C boundary 
exactly same number of times as in plain psycopg2. This is (also more 
important for performance) the case with write/read/readline to a 
socket, which never pass Python/C boundary until done or an error occurs.

> If you have an idea about how to allow a C callback to be registered
> in psycopg, your library could benefit of the whole nonblocking I/O
> support and still avoid the Python overhead. This, and any other
> comments, are welcome.

Off the top of my head I feel this can be done, but will look ugly.

One can pass around C pointer objects (CObject), which can in this case 
point to a C function in another module with some known signature.  This 
would be very un-Pythonic way to get things done, a dirty hack in fact, 
and how to define this signature is still a question, but it should work.



-- 

./lxnt