[Twisted-Python] Simplifying my StatusMonitor

Brad Bollenbach brad at bbnet.ca
Fri Jul 18 07:31:15 MDT 2003


On Fri, Jul 18, 2003 at 11:42:04AM +0800, Wari Wahab wrote:
> Brad Bollenbach wrote:
> 
> >Okay, in the usual XP fashion, I'm doing a spike to assess two use cases
> >for Twisted:
> >
> >1. Writing a simple monitor that checks the status of a response, to see
> >what it's like to write a foobar in Twisted.
> >[..snip..]
> >I did #1 this morning. It's 49 lines of Python, in what would have
> >otherwise been less than five of "normal", blocking code:
> >[..snip code..]]
> >How could I have made this simpler? What approach would you have taken
> >to solve this problem?
> > 
> >
> Although the code seems like a lot, but it looks like you've gained 
> something that does not block. For example, you can check a few sites 

I don't buy this. I'd sooner take 45 fewer lines of code that /do/
block, and add 3 more lines to make it run in a thread. This is just a
basic test, I shudder to think at the complexity that would be added to
monitor complex transactions.

However, I'm not saying that I don't like Twisted, I'm saying there must
be a better way, and I want those in the know to show me what I'm doing
wrong. :)

> concurrently this way.
> 
> I changed the code a bit so that I get more interesting results out of 
> it. And from the results, you see that the return of the status != the 
> order you called it, which is the nature of the internet.
> wari at minisync:~$ python testspike.py
> Got request for http://www.bbnet.ca/
> Got request for http://roughingit.wari.org/
> Got request for http://www.yahoo.com/
> Got request for http://www.twistedmatrix.com/
> hooray, got status 200 for http://roughingit.wari.org/
> hooray, got status 200 for http://www.twistedmatrix.com/
> hooray, got status 200 for http://www.yahoo.com/
> hooray, got status 200 for http://www.bbnet.ca/
> 
> The call I did is this:
> StatusMonitor().checkFor200OK('http://www.bbnet.ca/')
> StatusMonitor().checkFor200OK('http://roughingit.wari.org/')
> StatusMonitor().checkFor200OK('http://www.yahoo.com/')
> StatusMonitor().checkFor200OK('http://www.twistedmatrix.com/')
> #d.addCallback(lambda *a: reactor.stop())
> reactor.callLater(5, reactor.stop)

I'm very new to Twisted (I'm only 48 hours old in Twisted-time), but I
think you meant to use a DeferredList here. At any rate, this code
doesn't make things any simpler, which is what I'm really after (lazy,
impatience and all that).

--
Brad Bollenbach
BBnet.ca




More information about the Twisted-Python mailing list