Re: improving async support in psycopg
Jan Urbański <[email protected]> Sat, 27 Mar 2010 21:29:43 +0100
| Newsgroups | gmane.comp.python.db.psycopg.devel |
|---|---|
| Message-ID | <[email protected]> |
On 27/03/10 03:40, Jan Urbański wrote:
> On 27/03/10 03:21, Daniele Varrazzo wrote:
> Skimming over the patches I have a question: is it really necessary to
> add the callback feature into the C library? AFAICS the callback is
> executed on asynchronous cursors everytime there is a execute() attempt.
> Couldn't you just write a Python psycopg2.extensions.cursor subclass
> that overrides execute() by calling that callback?
I just tried using something like:
class GreenCursor(psycopg2.extensions.cursor):
def execute(self, sql, args=None):
ret = psycopg2.extensions.cursor.execute(self, sql, args)
gevent_wait_callback(self)
return ret
and then doing cur = conn.cursor(cursor_factory=GreenCursor) and your
gevent test worked without having to add the callback feature to the
factory. All it takes is some helper functions to wrap the basic async
support, which I think is the way to go: only make psycopg2 expose the
minimal interface and make the libraries wrap it the way the like.
Cheers,
Jan
_______________________________________________
Psycopg mailing list
[email protected]
http://lists.initd.org/mailman/listinfo/psycopg