Hi, if I run this script:
loop{
puts “hello”
sleep 1
}
It outputs “hello” every second.
But if I place it in a separate thread:
Thread.new do
loop{
puts “hello”
sleep 1
}
end
it prints it only one time and then exits.
Why is that?
Hi, if I run this script:
loop{
puts “hello”
sleep 1
}
It outputs “hello” every second.
But if I place it in a separate thread:
Thread.new do
loop{
puts “hello”
sleep 1
}
end
it prints it only one time and then exits.
Why is that?
Emil S. wrote the following on 16.08.2007 13:20 :
it prints it only one time and then exits.
Why is that?
You don’t wait for the Thread to stop to exit your program.
On 8/16/07, Emil S. [email protected] wrote:
Thread.new do
loop{
puts “hello”
sleep 1
}
endit prints it only one time and then exits.
Why is that?
When your program exits, the thread dies. Take a look at Thread.join
http://www.ruby-doc.org/core/classes/Thread.html#M000474
This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.
Sponsor our Newsletter | Privacy Policy | Terms of Service | Remote Ruby Jobs