[Twisted-Python] HowTo -- load a business-object in a Twisted Web Server ??

Moshe Zadka m at moshez.org
Mon May 26 12:08:54 EDT 2003

On Mon, 26 May 2003, "Thomas Weholt" <2002 at weholt.org> wrote:
> I need to load a business-object in a Twisted Web server serving static 
> content and rpys, and it should be available in all parts of the 
> application. It has to be able to run a method or methods at specified 
> intervals, fetching some files from the net, scanning a filesystem or 
> extracting data from a database, which in return will be available in 
> the business-object in the web-server. What is the Twisted-way of doing 
> this? The tasks the business-object will perform from time to time can 
> be time consuming and probably blocking too.
> Should a start it in a seperate thread? What ? I need clues or a small 
> example.

Please don't post in HTML to the list.

The correct Twisted way is to have an ApplicationService which does
all that, keeping track of tasks, and which has a "resource" attribute.
Deployment of that code is flexible, as it should be: one way would
be to add the ApplicationService to the Application, and in the .rpy
get the application, get the service by name and get the resource
from it.

I seriously doubt you "need" to perform blocking tasks, at least
in your code. Database can be abstracted with adbapi, scanning
a file system can easily be partitioned into small tasks, and
then you can use reactor.callLater(0,) to stay responsive and fetching
files from the net is easy in a nonblocking way (see web.client)
Moshe Zadka -- http://moshez.org/
Buffy: I don't like you hanging out with someone that... short.
Riley: Yeah, a lot of young people nowadays are experimenting with shortness.
Agile Programming Language -- http://www.python.org/

More information about the Twisted-Python mailing list