[Twisted-Python] Completely new to twisted - where to get some background?
Paul Moore
lists at morpheus.demon.co.uk
Mon Oct 21 13:48:01 MDT 2002
Jp Calderone <exarkun at meson.dyndns.org> writes:
> From this, I'd say that you're probably going to be a developer, an
> administrator, and a user. ;)
I sort of thought that might be the case :-)
> The current NNTP code lets you use one of two different backends - a
> pickle file or an RDBM (postgres is what was used to develop it). To serve
> news out of mbox files, you'll need to write another backend that implements
> the NewsStorage interface (twisted.news.database.NewsStorage), then hand
> this to either an NNTPServerFactory or a UsenetServerFactory (probably the
> former).
Thanks! That pointer was enough to get me started, and I managed to
get a simple "dummy" backend (serving one static article in one group)
up and running in half an hour! It's extremely easy, once you get the
picture.
> It would be nice if 'mktap news' could handle this, but it can't
> (yet), so you'll have to write a little more python to glue it all
> together. twisted.tap.news.updateApplication() is definitely
> something you'll want to look at.
Haven't done this yet, at the moment I'm just starting the server
running directly, not botyhering with mktap/twistd. That's my next job
(as far as learning Twisted goes - writing the backend I really want
probably has to go in there somewhere too :-))
I can see a few possible approaches - the simpler one seems to be to
write a new type of application so that you do "mktap pfmnews". This
seems like an unpleasant hack, though...
Better would probably be to patch Twisted (and submit the patch,
obviously :-)) to allow the "news" application to be more configurable
as regards backend type. My feeling is that this is a reasonable and
not too hard way to go.
I wonder, however, if it is somehow possible to "subclass" the
existing news application type, to add my own backend into it without
needing to patch Twisted. That would seem the best solution,
ultimately. However, I'm not at all familiar with this part of Twisted
yet, so I could easily have missed something simple.
> The Application Howto and the Server Howto are probably worth going
> over:
>
> http://twistedmatrix.com/documents/howto/application
> http://twistedmatrix.com/documents/howto/servers
>
> You shouldn't need to write a Factory or a Protocol to do what you want,
> but knowing how the pieces fit together will probably be beneficial.
It was indeed. Gave me a good place to start.
> Depending if you try to make "queries" to the mbox synchronous or not, the
> Deferred howto might be relevant as well:
>
> http://twistedmatrix.com/documents/howto/defer
>
> Twisted usually considers disk operations (and certainly memory
> operations) fast enough to not worry about this, though, so doing what the
> PickleStorage class does (defer.fail(), defer.succeed()) will probably work
> for you.
So far, the simple approach is working, but I'll keep this in mind...
> Twisted is definitely suited for this :) I'm not aware of a document that
> is directly relevant to what you want to do, because it's not too deeply
> related to Twisted. Hopefully what needs to be done will be clear after you
> check out the code I mentioned above.
Indeed, it became a lot clearer, very fast. I was getting bogged down
in concepts (Perspective Broker, reactors...) which didn't seem
relevant to me (and weren't, as it happened). Maybe some sort of
documentation roadmap ("If you are trying to do XXX, then start with
documents YYY, ZZZ") would be useful. Your suggestions certainly got
me on the right track, starting from "I want to implement a server",
and "I want to implement a *news* server, specifically".
Thanks for the help,
Paul.
--
This signature intentionally left blank
More information about the Twisted-Python
mailing list