Thanks for the quick response, this is what I wrote, but it doesn't seem
to work, no errors, but it just finishes the program without doing
anything. Where did I go wrong?
require 'thread'
buffer = SizedQueue.new(10)
producer = Thread.new do
File.open("urls.txt").each do |url|
buffer << url
end
end
consumer = Thread.new do
while buffer.num_waiting != 0
url = buffer.pop
#do screen scraping with url here
end
end
consumer.join
Robert Klemme wrote:
> 2009/5/26 Nabs Kahn <nabusman / gmail.com>:
>> I'm creating a screen scraping software and I want to have X (let's say
>> 10 for example) threads running simultaneously doing the scraping. The
>> program will access a text file containing an unknown number of URLs and
>> then scrape.
>>
>> My question is how do I setup the threads so that once a thread finishes
>> execution it picks up another URL and starts executing again.
>
> Create a Queue (require 'thread') and have your worker threads read
> URL's from it.
>
> Kind regards
>
> robert
--
Posted via http://www.ruby-forum.com/.