-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA512

On 11/9/11 1:07 AM, brettg wrote:
> I guess this is more of a design question, but I'm trying to use 
> Parallel to spawn 10 threads of the same process.
> 
> trunk = `cat pools`
> 
> trunk.each do |pool| Parallel.each(["#{pool}"], :in_threads=>10) {
> |k| `rsync -av user@machine:/#{k} /mnt/backup/#{k}` } end

Use threadify:
% gem i threadify

% cat a.rb
require threadify
# ... add some items for processing to mylist
result_listmylist.threadify do |item|
  # do what you want with item
end

# If you want 10 threads processing the result:
% time ruby -rthreadify -e 'puts (1..10).to_a.threadify(10) {|i|
sleep(1); i+1}'
2
3
4
5
6
7
8
9
10
11
ruby -rthreadify -e 'puts (1..10).to_a.threadify(10) {|i| sleep(1);
i+1}'  0.41s user 0.03s system 27% cpu 1.617 total


- -- 
All the best, Sandor Szs
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.11 (Darwin)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iQIcBAEBCgAGBQJOukw6AAoJEIiuFRwovs5r6boP/iNkioPOQNvZdx7arDVi6Zir
LylmmJeWna6Lf8U9xSGHzSSOzQJ1Be4OvnixeeqBCrKtmhOgp7XV60hSIm+C6Yx5
K331lQ6VYAk0T+J34rdl/J+2ATqLOyyheMjCce2Yjm8LsMMbJVBDz0Z+OhJRY15m
InAhL44Ofrm6BgRY1k9yY9Fqd6vosbqz5ptTFQtPy1zq5WwYq+6ZN++cQzD/ndRP
i3RTzWcDsfSA7q7Zylm7QIclTbHajGzg0scHO7hDhTALdyVzmov24shMkuCrx/4R
d/gnKB8GuJwFwN7AiPQa8hHFqnkKOlronTuMieGfi12qbXDe5rC3aq+d8jdL20ZT
C5LLpsU1eQeXK4FJSCokA0kwbH+9TNk2WfF2ZXr8H8/DrUj9/DcWzkhX3P2Kfl13
eKCzPi31M2b8ZEpEG9xz6yScQl5zheSOZbQqwa7IY/twehknOS3/XOT05DUwXvgq
HwMzQHMU8q03+QMIHbSgP5Wrx9GkhQljRcjOB5b0wz6uniiwz1cZ9wlxNzsESEW/
78XamkcGBDzRL4NWz5CnSd1csxsMyTX8R4CJRWLFLohS0g0xBHxMJuloPI6GLszf
SdJL+LHwWVwteexBK3ZXf66RFbWBXpEG0ikzCUHZxr8A5nGrrUpCEwrFbsa0ATWx
xJjLH8Xr82C5v86YVju/
=/fzL
-----END PGP SIGNATURE-----