[#386100] Numeric#coerce docs are disaster — 7stud -- <bbxx789_05ss@...>

num.coerce(numeric) =E2=86=92 array

14 messages 2011/08/02

[#386114] Documentation Improvement Proposal — Chris White <cwprogram@...>

=3D Issues =3D

24 messages 2011/08/02
[#386115] Re: Documentation Improvement Proposal — Steve Klabnik <steve@...> 2011/08/02

I reeeeeealy dislike user comments on documentation. It's one of the

[#386117] Re: Documentation Improvement Proposal — Phillip Gawlowski <cmdjackryan@...> 2011/08/02

On Tue, Aug 2, 2011 at 7:39 PM, Steve Klabnik <steve@steveklabnik.com> wrot=

[#386118] Re: Documentation Improvement Proposal — Steve Klabnik <steve@...> 2011/08/02

> What's wrong with stealing WikiPedia's procedures? The model works

[#386119] Re: Documentation Improvement Proposal — Chris White <cwprogram@...> 2011/08/02

On Aug 2, 2011, at 11:00 AM, Steve Klabnik wrote:

[#386123] Re: Documentation Improvement Proposal — Steve Klabnik <steve@...> 2011/08/02

Apologies, I've just responded to everyone in-line.

[#386231] Brainstorming ideas how to improve Ruby's documentation — Marc Heiler <shevegen@...>

The title is misleading...

42 messages 2011/08/05
[#386233] Re: Brainstorming ideas how to improve Ruby's documentation — "Fred L." <f.linard@...> 2011/08/05

Hello,

[#386235] Re: Brainstorming ideas how to improve Ruby's documentation — Alexander Litvinovsky <alexander.litvinovsky@...> 2011/08/05

What are you talking about? Ruby has a nice docs, railsapi.com for example.

[#386297] Help out with the next version of ruby-lang.org — Magnus Holm <judofyr@...>

https://github.com/rubylang/ruby-lang.org

11 messages 2011/08/07

[#386341] Exceptional Ruby and Metaprogramming Ruby has anyone picked these up? — Kevin <darkintent@...>

I'm thinking of picking up these two books and was wondering if anyone

11 messages 2011/08/09

[#386378] ruby installation — "Momodou J." <modou75alieu@...>

how to implement this in windows :

16 messages 2011/08/09

[#386401] *WHY* does this not work? — serialhex <serialhex@...>

ok, so code:

23 messages 2011/08/09
[#386403] Re: *WHY* does this not work? — "Darryl L. Pierce" <mcpierce@...> 2011/08/09

On Wed, Aug 10, 2011 at 03:52:59AM +0900, serialhex wrote:

[#386404] Re: *WHY* does this not work? — serialhex <serialhex@...> 2011/08/09

On Tue, Aug 9, 2011 at 3:05 PM, Darryl L. Pierce <mcpierce@gmail.com> wrote:

[#386480] Odd regexp behavior — Glen Holcomb <damnbigman@...>

I'm running 1.9.2-p180

16 messages 2011/08/10

[#386506] Distributing Ruby program as a standalone executable (exe) for windows — Michelle Pace <michelle@...>

Hello there,

10 messages 2011/08/11

[#386539] Online tutor for Ruby — T J Pereira <tj5155@...>

I am finding it difficult to apply the RUBY program. Its because i have

18 messages 2011/08/12
[#386541] Re: Online tutor for Ruby — Phillip Gawlowski <cmdjackryan@...> 2011/08/12

On Fri, Aug 12, 2011 at 6:00 AM, T J Pereira <tj5155@tm.net.my> wrote:

[#386637] class inheritance and class constants — Iñaki Baz Castillo <ibc@...>

------------------------

16 messages 2011/08/14

[#386784] Green Shoes v1.0 released — ashbb <ashbbb@...>

Hello, everyone.

15 messages 2011/08/18
[#392062] Re: Green Shoes v1.0 released — Barry Yu <yubarry@...> 2012/01/09

why do I get this error?

[#386796] Searching in a directory — Yu Yu <htwoo@...>

Hello,

21 messages 2011/08/18

[#386893] Gritty Details of super() — luke gruber <luke.gru@...>

Hey guys,

18 messages 2011/08/21

[#386900] Possble bug in Ruby parser (Fixnum#times within "case" statement) — Iñaki Baz Castillo <ibc@...>

Hi, I cannot find an explanation for the following issue so I think it's a =

15 messages 2011/08/21
[#386901] Re: Possble bug in Ruby parser (Fixnum#times within "case" statement) — Ryan Davis <ryand-ruby@...> 2011/08/21

[#386903] Re: Possble bug in Ruby parser (Fixnum#times within "case" statement) — Iñaki Baz Castillo <ibc@...> 2011/08/21

2011/8/22 Ryan Davis <ryand-ruby@zenspider.com>:

[#386920] New to Ruby some problems — jack jones <shehio_22@...>

I am new to Ruby, My mother tongue is C++ .. I have too many problems I

21 messages 2011/08/22

[#386949] Want to get involved with this doc stuff? I'm making it even easier — Steve Klabnik <steve@...>

Hey guys-

9 messages 2011/08/22

[#387058] How the access the values of this result — QAS WM <qaiserwali@...>

I am getting the following as a result of a script I run.

11 messages 2011/08/26

[#387070] overloading methods question please? — jack jones <shehio_22@...>

def do_something(a as Array)

11 messages 2011/08/26

[#387138] String#split resets regex captures variables (Ruby 1.8.7) — Olivier Lance <bestiol@...>

Hi,

10 messages 2011/08/29

[#387196] SAMSUNG to produce "Ruby on Rails in Silicon" System on a Chip — Ilias Lazaridis <ilias@...>

(public draft)

9 messages 2011/08/31

[#387197] Prepend a character to a string in ruby — ruby rails <rubyonrails4me@...>

Hi,

10 messages 2011/08/31

[#387212] GUI programming — Samuel Mensah <sasogeek@...>

Is ruby GUI programming something that will come along as I study ruby

19 messages 2011/08/31
[#387230] Re: GUI programming — Alexey Petrushin <axyd80@...> 2011/08/31

I believe right now it's better to stay with console, there's no Ruby

Re: Multithreading in Ruby

From: Kevin Curtin <kevincurtin88@...>
Date: 2011-08-22 17:35:28 UTC
List: ruby-talk #386938
unsubscribe

2011/8/22 Jes=FAs Gabriel y Gal=E1n <jgabrielygalan@gmail.com>

> On Mon, Aug 22, 2011 at 6:46 PM, Nabs Kahn <nabusman@gmail.com> wrote:
> > Hi, I'm relatively new to ruby and threading in general. I'm trying to
> > get the following code to work. Essentially, the program scrapes data
> > from a site which has a list of urls on the first page (and more list
> > pages can be accessed by hitting next) and each url in the list needs t=
o
> > be followed as well.
> >
> > So what I would like to do is create 5 concurrent threads: Thread 1
> > would download the list page as a Mechanize page object and queue it,
> > hit next and download the next page as a Mechanize page object and queu=
e
> > it, etc. Thread 2 would take the queue from Thread 1 and start to
> > extract the required data, i.e. the urls and queue them into a new
> > queue. Thread 3 would take the queue from Thread 2 and download the pag=
e
> > each url points to and save it as a Mechanize page object and queue it
> > into another queue. Thread 4 would take the queue from Thread 3 and
> > extract the necessary data, format it and queue it into yet another
> > queue. And finally, Thread 5 will take the queue from Thread 4 and writ=
e
> > the data to a file.
> >
> > At least, that is in theory... So I wrote the following program, howeve=
r
> > only the first Thread seems to be queueing and the rest don't work.
> > Please let me know if I'm missing something.
> >
> >  rank_pages_queue =3D Queue.new
> >  items_queue =3D Queue.new
> >  item_pages_queue =3D Queue.new
> >  finished_items_queue =3D Queue.new
> >
> >  mech_page =3D get_page(url)
> >  rank_page_download =3D Thread.new do
> >    while mech_page
> >      rank_pages_queue << mech_page
> >      mech_page =3D hit_next(mech_page)
> >    end
> >  end
> >
> >  rank_page_extract =3D Thread.new do
> >    while rank_pages_download.alive?
> >      rank_page =3D rank_pages_queue.pop
> >      items_queue << get_rank_name_url(rank_page)
> >    end
> >  end
> >
> >  item_page_download =3D Thread.new do
> >    while rank_page_extract.alive?
> >      items =3D items_queue.pop
> >      items.each do |item_arr|
> >        item_pages_queue << [item_arr, get_page(item_arr[2])]
> >      end
> >    end
> >
> > Thanks in advance. And I'm running Ruby 1.8.7 on Snow Leopard.
> >
> > --
> > Posted via http://www.ruby-forum.com/.
> >
> >
>
> I'm not really sure what your problem is, but I see an issue and
> something that I'd do differently. If you are experiencing that the
> program ends without anything done, it's because you need to wait for
> the threads to complete. You can do that with the join method, or the
> value method, if you need a return value from the thread. Also, I
> think there's something wrong with your logic of calling alive?. It
> can happen that the thread is still alive but it will not enqueue
> anything else because it's finished already. If this happens, that
> thread will block in the call to queue.pop forever. A better
> alternative is to queue a special object which will signal the
> consumer that it has to finish. Something like:
>
> require 'thread'
>
> def process
>  sleep(rand)
> end
>
> queue =3D Queue.new
>
> puts "creating first"
> first =3D Thread.new do
>  ["work", "more work", "yet some more", :finish].each do |work|
>        puts "first thread is processing..."
>        process
>        puts "queuing #{work}"
>        queue << work
>  end
> end
> puts "creating second"
> second =3D Thread.new do
>  while (work =3D queue.pop) !=3D :finish
>    puts "got #{work} to do. processing it..."
>    process
>  end
> end
>
> first.join
> second.join
> puts "finished"
>
>
> $ ruby queues.rb
> creating first
> first thread is processing...
> creating second
> queuing work
> got work to do. processing it...
> first thread is processing...
> queuing more work
> got more work to do. processing it...
> first thread is processing...
> queuing yet some more
> first thread is processing...
> queuing finish
> got yet some more to do. processing it...
> finished
>
> In this little example, I used the symbol :finish to signal that the
> other thread should finish and not wait for anything else in the
> queue. You can use any other thing you want. For example, if the
> consumer can receive any arbitrary object, I've seen people enqueue
> the actual queue object to signal the end. In my example a symbol was
> enough and a simple solution. Also note how I joined the two threads
> at the end, to avoid the main thread exiting the program before the
> threads are finished. I also added a little process method that sleeps
> a random amount of time, to simulate the actual work.
>
> Hope this helps,
>
> Jesus.
>
>

In This Thread