From: ara.t.howard@... Date: 2006-10-27T05:26:15+09:00 Subject: Re: threads On Fri, 27 Oct 2006, Francis Cianfrocca wrote: > On 10/24/06, Brad Tilley wrote: >> >> I'm rewriting some old Python scripts in Ruby. Just to learn a bit more. >> I want to thread this code to check websites concurrently. Could somone >> offer advice? What are reasonable limits on threads in Ruby? > > > > Here's an EventMachine code sample that should do what you need. Notice, > this code is nonthreaded, but it still does all the HTTP GETs > simultaneously. Of course you'll want to do something more interesting in > the http.callback block. > > #------------------------------------- > > require 'rubygems' > require 'eventmachine' > > $addrs = [ > "www.apple.com", > "www.cisco.com", > "www.microsoft.com" > ] > > def scan_addr addr > http = EventMachine::Protocols::HttpClient.request( > :host => addr, > :port => 80, > :request => "/" > ) > > http.callback {|response| > puts response[:status] > puts response[:headers] > puts response[:content].length > } > end > > EventMachine.run { > $addrs.each {|addr| scan_addr addr} > } what would the preferrer way by to shared data from http.callback? does it need protection? how about sharing with ruby green threads? cheers. -a -- my religion is very simple. my religion is kindness. -- the dalai lama