[Twisted-Python] Polling a resource on another computer with Twisted

glyph at divmod.com glyph at divmod.com
Tue May 1 23:23:08 MDT 2007


On 01:48 am, rampeters at gmail.com wrote:
>I am looking for some guidance on how to poll a resource on another
>computer using twisted.  Poll a remote resource, if a task is
>available, I need to perform it on the twisted machine, not on the
>remote resource machine.  Can anyone tell me how I can do this.
>Twisted event loops only listens for incoming.  I need to go out and
>check the resource and begin processing.

This question is extremely open-ended.  I could think of maybe 50 ways 
to implement this functionality as specified, and I'm not sure exactly 
what you're thinking.

Twisted does listen for incoming *events*, but I think what you mean is 
that it listens only for incoming *connections*.  If what you mean is 
simply "how do I connect to another host as a client", see this 
document:

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

If what you mean is "how do I do something, such as check a remote 
resource, periodically", you might want to use Twisted's LoopingCall 
object:

http://twistedmatrix.com/documents/current/api/twisted.internet.task.LoopingCall.html

If what you mean is "how do I stop my program and wait for something to 
happen", you don't need to.  Simply ask the remote computer about the 
resource you are polling (by establishing a client connection and 
writing some bytes to it, for example), and then wait for the reactor to 
tell you that it has responded.  If you want to establish a timeout, set 
up a timed call using reactor.callLater, and cancel it if the response 
arrives first.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: </pipermail/twisted-python/attachments/20070502/2094f426/attachment.html>


More information about the Twisted-Python mailing list