[Twisted-Python] "glue" problem

Phil Mayers p.mayers at imperial.ac.uk
Sat Apr 19 11:19:44 MDT 2008


Dr Pythoniac wrote:
> Hi all

When posting a new topic, please don't use reply-to on a previous
different topic, it breaks threading.

> 
> concerning twisted.web:
> 
> How do I run once-per-application stuff ?
> 
> Assume, I want to put sth into the static.Registry or  I want to read
> in some application data from a file, so that every resource can use
> it.
> 
> My main problem can be split in two:
> 
> - where do it do it (using twistd) ? Please no complicated plugin (or
> alike) suggestions. I'm seeing red just hearing 'zope' ...

Assuming you are using a .tac file, you might do something like this in
"application.tac":

from twisted.application import service, strports

import mycode

application = service.Application('myapp')
services = service.IServiceCollection(application)

# do startup code here
mycode.doStartupStuff()

site = mycode.site()
web = strports.service('tcp:80', site)
web.setServiceParent(services)

...then run the "tac" file with:

twistd -oy application.tac

...this is such a simple solution that I guess you are having more basic
misunderstandings.


> 
> 
> - how can resource scripts use it ?

What does this mean?

> 
> Probably this is an idiots question but I have sth. like 8
> Browsertabs open with twisted "docu" and getting more and more
> confused by hunting pieces of information that are just splattered
> all over the site.

Have you read the finger tutorial from start to end, and understood it?

> 
> Additional: Is there any docu about twistd ? How can I use all its
> miracles rather than just dumbly guess and try an err and try and err
> and ... ?

http://twistedmatrix.com/projects/core/documentation/howto/application.html

...describes the contents of a ".tac" file, the recommended way to use 
twistd. If you could be more specific about *what* you don't understand, 
what you've tried already, why it didn't work and with what error 
messages, I can perhaps be more helpful.




More information about the Twisted-Python mailing list