[Twisted-Python] Creating a new selectable (for Pg async interface)

Itamar Shtull-Trauring twisted at itamarst.org
Sun Dec 15 12:30:40 EST 2002


On Sun, 15 Dec 2002 17:13:49 +0100
Gerhard Häring <haering_python at gmx.de> wrote:

> I don't really know much about twisted, so please correct me if this
> is wrong:
> 
>     A reactor is the Twisted main loop, which selects on selectables,
>     and invokes doRead() on them when data is available.

That is correct.

> Now I'm at the point where I'd like to try this code out. *But*
> obviously something is still missing. I believe my PgAsyncConn would
> need to be registered with the reactor?! Is this true and if yes, how
> do I do it?

If you look at abstract.FileDescriptor.__init__, you'll see it wants to
get a reactor as an argument, and if not uses the global one. In general
the code seems ok, except that you really ought to be using Deferreds
instead of callback/errback pairs. See
http://twistedmatrix.com/documents/howto/defer for details.

> Btw. I'll try to keep my new baby interface-compatible with
> twisted.enterprise.adbapi as much as possible.

Cool!

> Next question: I'd like to try my code out. Is there a good way to
> test this under Twisted, apart from writing a little server like the
> Echo example of the docs, and trying to call PgAsyncConn from it?

Well, look at how we do tests in twisted.test - you can write a unit
test suite for your code, with the limitation of course that you'd need
a live postgresql server to test it.

-- 
Itamar Shtull-Trauring    http://itamarst.org/
Available for Python, Twisted, Zope and Java consulting
***> http://VoteNoWar.org -- vote/donate/volunteer <***




More information about the Twisted-Python mailing list