2013-04-01 2 views
0

누군가 다음 코드가 전달 된 블록을 생성하지 않는 이유를 설명 할 수 있습니까?데몬 젬으로 코드 블록 실행

require 'daemons' 

t = Daemons.call do 
    # This block does not start 
    File.open('out.log','w') do # code don't get here to open a file 
    |fw| 
    10.times { 
     fw.puts "=>#{rand(100)}" 
     sleep 1 
    } 
    end 
end 
#t.start # has no effect 
10.times { 
    puts "Running ? #{t.running?}" # prints "Running ? false" 10 times 
    sleep 1 
} 
t.stop 
puts 'finished' 

루비 1.9.3p392, x86_64의 리눅스

답변

0

동시 프로그래밍을위한 Thread을 실행하려고하지 않는 당신은 있는지?

f = File.open('out.log', 'w') 
t = Thread.new do 
    10.times { 
    f.puts "=>#{rand(100)}" 
    sleep 1 
    } 
end 
10.times { 
    puts "Running ? #{t.alive?}" 
    sleep 1 
} 
t.exit 
puts 'finished' 
:

는 여기 Thread 구현의 모습거야