[Twisted-Python] Some problems with twisted

Moshe Zadka twisted at zadka.site.co.il
Tue Dec 2 05:01:41 EST 2003


On Tue, 2 Dec 2003, Pieter Claerhout <Pieter.Claerhout at Creo.com> wrote:

> 2. During the execution of the doProcessing function, it's impossible to
> stop the application with e.g. CTRL+BREAK. Is there a way around this?

That's the first sign of problems: "during" a function call is a perceptable
time.

Here's code which would do the right thing, completely untested.
Notice how calculate, which would do the MySQL dance [probably
a bad idea to use SQL for these things], is only called when
the data is ready.

from twisted.application import service, internet
from twisted.web import server, static, client

def ProcessingService():
    return internet.TimerService(_doProcessing,
                                 ['http://www.yellowduck.be/',
                                  'http://www.beachshop.be/'])

def _doProcessing(urls):
    def calculation(data):
        pass # do something here
    for url in urls:
        client.getPage(url).addCallback(calculation)

def WebAdminService():
    return internet.TCPService(9119, server.Site(static.File('htdocs')))

application = service.Application('myapp')
for s in [ProcessingService(), WebAdminService()]:
    s.setServiceParent(application)




More information about the Twisted-Python mailing list