From: Francis Cianfrocca Date: 2006-10-27T05:12:24+09:00 Subject: Re: threads ------=_Part_30318_5740833.1161893542557 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Content-Disposition: inline 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} } #------------------------------------------------- ------=_Part_30318_5740833.1161893542557--