[Twisted-Python] Twisted is confusing...but I'm not giving up yet!
glyph at twistedmatrix.com
Thu Apr 25 02:15:01 EDT 2002
On Thu, Apr 25, 2002 at 01:01:21AM +0800, Mukhsein Johari wrote:
> Hello everyone,
> I'm new here. I thought trying to use zope in 1.x days was confusing but
> boy...twisted is realy out there. I can serve static web pages and do some
> cgi stuff but I'm more interested in making web-applications, primarily.
Glad to hear you're giving it a try. twisted.web has been lacking in
direction for a little while, but hopefully Donovan will be answering
some of these questions in depth. Take a look at his "Blog" application
> The thing is, from the docs I've read (and that's pretty much all in the
> distro) I'm still confused about what goes where and what to use. It seems
> the Twisted Framework can be used for just about anything except make coffee!
Yes, indeed. All you have to do in order to use Twisted for something
is write lots of code ;-).
> I think there-in lies the "problem". It's overwhelming for the new user. It
> would be nice if I could make a step-by-step tutorial. And I _will_ - if
> only I can understand it first. When I first got the "hang" of zope, I made a
> tutorial that takes the user from zero to a functioning publicly postable
> job-board with searching facilities. It illustrated zopes potential to a
> newbie using some basic components (custom zclasses).
Step-by-step tutorials to "twisted" are probably a bad idea. If you are
looking to write web applications, that's one specific facet of Twisted,
but keep in mind that it can be used at multiple levels; writing a web
application in Twisted is very different from Zope; we do not offer a
comprehensive web development framework. (Yet.)
> I'd like to make a similar tutorial for Twisted. If I can hack it, that is...
HOORAY. We need a good writer who can dedicate some time to this. I
hope that we can be responsive enough in answering your questions :).
> Basically, I'd have a bunch of classes, each has a "view" method ("display()"
> in Twisted?) and some other methods that would implement some kind of set and
> get functionality to the objects. (I have no idea how to do "searching" in
> Twisted at all). Btw...how do I implement persistence?
As it stands, all your objects will be dumped into one big pickle; so
just implement __getstate__ if you need to do something special;
otherwise, don't :-).
> I have a job-board instance that contains multiple job-posting instances. So
> that when you call the job-board's "view", it iterates over the job-posting
> instances there-in and calls their individual "view" methods. The job-board's
> "view" method creates a skeleton where the individual job-posting instances'
> "view" method "slots in".
Are you looking to back this with a database or just in-memory objects?
> In zope, I used zclasses to implement it (the tutorial was a zclass tutorial).
In twisted, you would likely use regular Python classes to implement it;
most likely (at this point) from twisted.web.widgets; although
the new twisted.web.domtemplate is the future.
> So ZODB pretty much took care of persistence automatically for me. How do I
> do object persistence in Twisted?
(See above, and...) if you are looking for something like ZODB, Twisted
doesn't offer it. Our approach is: either you need a database, or you
need objects. If you need an object database with all the attendant
trappings, using ZODB is probably your best bet; but if you need just a
reasonable quantity of objects persisted, just use the Application class
as the root of your system, and have it automatically persist.
If you require a relational databse, see twisted.enterprise; especially
twisted.enterprise.adbapi and twisted.enterprise.row. These are still
works in progress but there is a basic outline there for how a
database-backed application would be written.
> Also...what is "coil"? And how do I use it? It seems to have the same sorta
> modules that is in twisted.tap but I can't figure it out. From the
> literature, I think coil (or is it plugin?) is Twisted's way of doing zope's
> "python-based Products". Am I wrong?
That's pretty close to accurate; except for the fact that Products are
specifically web services and COIL provides configuration for
> Is there an analogous thingamajig to zope's zodb in Twisted?
No. Nor do we have plans for it. At one point, I thought that it might
be possible to improve upon the ZODB; after implementing some prototypes
and trying to devise a strategy I came to the conclusion that ZODB is
pretty darn good for what it does, and that the perceived deficiencies I
wanted to correct are inherent to object databases. Still, I find that
when one has a large amount of data to persist, a non-OODBMS strategy is
best. I do have a peculiar perspective though, because the datasets I
have to work with are usually either VERY large or VERY small.
Still, ZODB is good at that. itamar's work on integrating Twisted and
Zope will hopefully make that easy.
> Mukhsein Johari
I don't think that feeling ever goes away -- I've been *writing* Twisted
code for two years and I still feel dazed ;-). Maybe you can help by
documenting some of this stuff properly!
| <`'> | Glyph Lefkowitz: Travelling Sorcerer |
| < _/ > | Lead Developer, the Twisted project |
| < ___/ > | http://www.twistedmatrix.com |
More information about the Twisted-Python