Twisted Question

Moshe Zadka m at moshez.org
Sat Jun 7 09:19:15 EDT 2003


First of all, standard response: ask questions about Twisted on the
Twisted mailing list. Most Twisted developers do not hang around here.

On Sat, 07 Jun 2003, "Ed Young" <ejy712 at comcast.net> wrote:

> I need to be able to have a short process start at timed
> intervals which is able to start outbound socket connections.
> It needs to start a client connection to another server.
> 
> How do I get a process to start at timed intervals that is a
> part of the Twisted framework?  I haven't been able to get
> this from the manual or API reference provided by Twisted.

Probably a little wrapper on reactor.callLater. I feel the best way
to go about these things is usually with ApplicationServices:

untested code:

from twisted.internet import app, reactor

class StartConnectionTo(app.ApplicationService):

    def __init__(self, host, port, factory, time, *args, **kw):
        app.ApplicationService.__init__(self, *args, **kw)
        self.host = host
        self.port = port
        self.factory = factory
        self.time = time

    def startService(self):
        self._startConnecting()
    
    def _startConnecting(self):
        reactor.connectTCP(self.host, self.port, self.factory)
        reactor.callLater(self.time, self._startConnecting)

    def stopService(self):
        self.delayed.cancel()

Of course, I'm not familiar with the exact needs, so you may want more
stuff (for example, have a new factory produced each time is a frequent
need, and would not be hard...or you may want to let the service know
if you fail connection, etc. etc.)

Further resources: the Delayed call HOWTO, the Client HOWTO, the Application
HOWTO, all in your Twisted tarball or on the website.
-- 
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 Python-list mailing list