Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.ruby > #4089

Re: Threading Loops

From Roy Zuo <roylzuo@gmail.com>
Newsgroups comp.lang.ruby
Subject Re: Threading Loops
Date 2011-05-07 18:42 -0500
Organization Service de news de lacave.net
Message-ID <20110507234213.GA29128@bender> (permalink)
References <670f5be69524ccbfc188e9062e65f645@ruby-forum.com>

Show all headers | View raw


It is very convenient to use Thread in Ruby, but maybe you should first get rid
of pic_numb self-increment statements.

    pic_names.collect.with_index do |name, pic_numb|
        Thread.new do 
            print ' . '
            new_name = batch_name + pic_numb.to_s + ' .jpg'
            File.rename name, new_name
        end
    end.each{ |thread| thread.join }

Roy

On Sun, May 08, 2011 at 08:20:07AM +0900, Bobby S. wrote:
> I understood how to thread functions, but I don't understand how to
> implement it outside of that. I am trying to make a picture re-namer and
> I want to thread the renaming part to speed it up.
> 
> 
> pic_names = Dir["{E://**/*.{JPG, jpg}"]
> pic_numb = 1;
> batch_name = "test"
> 
> #Want to thread this part.
> pic_names.each do |name|
>   print ' . '
>   new_name = batch_name + pic_numb.to_s + ' .jpg'
>   File.rename name, new_name
>   pic_numb += 1
> end
> 
> Thanks in advance.
> 
> -- 
> Posted via http://www.ruby-forum.com/.
> 

-- 

Back to comp.lang.ruby | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

Threading Loops "Bobby S." <kajisakka@gmail.com> - 2011-05-07 18:20 -0500
  Re: Threading Loops Roy Zuo <roylzuo@gmail.com> - 2011-05-07 18:42 -0500
  Re: Threading Loops "Bobby S." <kajisakka@gmail.com> - 2011-05-07 19:03 -0500
    Re: Threading Loops 7stud -- <bbxx789_05ss@yahoo.com> - 2011-05-07 21:54 -0500
      Re: Threading Loops Robert Klemme <shortcutter@googlemail.com> - 2011-05-08 12:53 +0200
  Re: Threading Loops "Bobby S." <kajisakka@gmail.com> - 2011-05-07 20:04 -0500
  Re: Threading Loops "Bobby S." <kajisakka@gmail.com> - 2011-05-07 20:48 -0500
    Re: Threading Loops 7stud -- <bbxx789_05ss@yahoo.com> - 2011-05-07 21:16 -0500
      Re: Threading Loops Robert Klemme <shortcutter@googlemail.com> - 2011-05-08 12:56 +0200
  Re: Threading Loops 7stud -- <bbxx789_05ss@yahoo.com> - 2011-05-07 20:56 -0500
    Re: Threading Loops Christopher Dicely <cmdicely@gmail.com> - 2011-05-07 22:36 -0500
  Re: Threading Loops Kevin Bullock <kbullock+rubyforum@ringworld.org> - 2011-05-07 21:27 -0500
  Re: Threading Loops "Bobby S." <kajisakka@gmail.com> - 2011-05-07 22:12 -0500
  Re: Threading Loops Brian Candler <b.candler@pobox.com> - 2011-05-08 09:07 -0500

csiph-web