| em-dash | are there any compelling reasons not to spin off threads by way of #map (eg, 'threads = urls.map { |url| Thread.new(url) do |u| end }; threads.each { |thr| thr.join }')? most of the threading examples I see use something like 'threads << Thread.new' inside a loop |
| manveru | em-dash: it's cool |
| em-dash | I also ask because I'm seeing some strange behavior: ruby seems to spin off 3 threads in quick succession, and then launches another as each one finishes. Not sure that's what's going on, but it's definitely not firing them all off and then waiting for them all to finish manveru: you're saying #map should work, right? |
| manveru | sure |
| em-dash | ok, thanks I'll do more tests :) |
| manveru | what are your threads doing? |
| em-dash | well, they launch ssh in a subshell (via backticks), hopefully 8 separate subshells simultaneously, but I'm only seeing 3 at a time |
| motion | em-dash: you should look at net-ssh |
| em-dash | sort of a lame 'fork', but cross-platform compatible |
| motion | em-dash: you can do 8 ssh sessions in 1 connection ... |
| em-dash | yeah, you're right, I'm moving towards net-ssh, but this is working now in the meantime |
| manveru | that won't work well in ruby... |
| em-dash | manveru: oooh, I hadn't thought of that manveru: why won't it work well? |
| manveru | your processes block each other you really are better off with net-ssh |
| em-dash | can you elaborate why the processes block each other? |
| wyhaines | em-dash: Yep. That's why you are seeing the behavior you are seeing. After three threads are created, the first creates the 'ssh' and all the threads are then blocked until it finishes. |
| motion | em-dash: ruby 1.8 isnt truly threaded... it fakes it |
| em-dash | so backtick are blocking calls? oops |
| manveru | em-dash: because they are green and ssh is quite... possessive :) |
| motion | they should call them red threads, since they stop everything ;) |
| em-dash | I got the green threading thing, but I thought that subshells were non-blocking (don't know why I thought that, exactly) |
| oGMo | heh |
| motion | em-dash: `` do return stuff ... its impossible for it to not block em-dash: you CAN make it non blocking by doing `cmd &` and putting hte command in the background |
| em-dash | I mean that it I thought it wouldn't block a separate green thread |
| manveru | wow... |
| em-dash | I know it blocks the current thread, didn't realize that it blocks the process |
| manveru | i just found a totally sweet rubyquiz :) |
| motion | em-dash: if they were real threads they wouldnt block ... manveru: url ? |
| manveru | http://attachr.com/7699 |
| em-dash | ok, now it's sinking in... manveru's not joking. I'd be *way* better off with net-ssh |
| manveru | took me 30 minutes due to a really stupid mistake :) |
| motion | wtf |