#ruby-lang - Tue 24 Apr 2007 between 00:03 and 00:13

em-dashare 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
manveruem-dash: it's cool
em-dashI 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?
em-dashok, thanks
I'll do more tests :)
manveruwhat are your threads doing?
em-dashwell, they launch ssh in a subshell (via backticks), hopefully 8 separate subshells simultaneously, but I'm only seeing 3 at a time
motionem-dash: you should look at net-ssh
em-dashsort of a lame 'fork', but cross-platform compatible
motionem-dash: you can do 8 ssh sessions in 1 connection ...
em-dashyeah, you're right, I'm moving towards net-ssh, but this is working now in the meantime
manveruthat won't work well in ruby...
em-dashmanveru: oooh, I hadn't thought of that
manveru: why won't it work well?
manveruyour processes block each other
you really are better off with net-ssh
em-dashcan you elaborate why the processes block each other?
wyhainesem-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.
motionem-dash: ruby 1.8 isnt truly threaded... it fakes it
em-dashso backtick are blocking calls? oops
manveruem-dash: because they are green
and ssh is quite... possessive :)
motionthey should call them red threads, since they stop everything ;)
em-dashI got the green threading thing, but I thought that subshells were non-blocking (don't know why I thought that, exactly)
motionem-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-dashI mean that it I thought it wouldn't block a separate green thread
em-dashI know it blocks the current thread, didn't realize that it blocks the process
manverui just found a totally sweet rubyquiz :)
motionem-dash: if they were real threads they wouldnt block ...
manveru: url ?
em-dashok, now it's sinking in... manveru's not joking. I'd be *way* better off with net-ssh
manverutook me 30 minutes due to a really stupid mistake :)

Page: 2 9 16 23 30 37 44