[Twisted-Python] minor beginner questions
Andrew Bennetts
andrew-twisted at puzzling.org
Fri Jul 4 08:42:09 MDT 2003
On Fri, Jul 04, 2003 at 04:13:54PM +0200, Achim Domma (ProCoders) wrote:
> Hi,
>
> playing around with twisted.web, I have some minor questions:
>
> - In another message a function 'deferToThread' was mentioned. I tought that
> somethink like must be available in twisted but could not find it. Is there
> an example on how to use it?
It's easily found in the API docs (e.g. search in the "everything" frame at
http://twistedmatrix.com/documents/TwistedDocs/current/api/), or even by
grepping the source[1]. To save you some time, it's in
twisted.internet.threads.
It's also described (with a brief example) in
http://twistedmatrix.com/documents/howto/threading -- if you understand
Deferreds, there's really nothing to it.
-Andrew.
[1] "Exuberant Ctags" (http://ctags.sf.net/) is your friend -- I can type
:tag deferToThread
in vim, and be taken straight to where deferToThread is defined in the
source. I've indexed my entire /usr/lib/python2.2 with ctags, and it's
proven incredibly useful.
> - Is it possible to create resources in my startup script, where I create my
> application. Instead of having a simple *.rpy with
> resouce=SomeClassInstance() I would like to use addChild on the root of my
> app. Is that possible?
Of course, e.g.
from twisted.web import resource, server
from twisted.internet import app
from myApp import MyClass
application = app.Application('MyApp')
root = resource.Resource()
root.putChild('app', MyClass())
application.listenTCP(80, server.Site(root))
> - If I want to keep a Connection to a ZODB, should I store it in the
> registry or is there a besser place to store it?
I suspect the best place would be in an ApplicationService -- but someone
else that knows what they're talking about should probably answer this.
-Andrew.
More information about the Twisted-Python
mailing list