multithreading - Why does exiting a Ruby thread kill my whole program? -
i have piece of code:
puts "start" loop thread.start puts "hello thread" exit end text = gets puts "#{text}" end puts "done"
what expect seeing "start" followed "hello thread" , enter input echoed me. instead "start" , "hello thread" , program exits.
from documentation on exit
:
terminates thr , schedules thread run. if thread marked killed, exit returns thread. if main thread, or last thread, exits process.
but thought spawned new thread? why exiting main process?
you're looking @ thread#exit
documentation. kill
kernel#exit
terminates ruby script.
puts "start" loop thread.start puts "hello thread" thread.exit end text = gets puts "#{text}" end puts "done"
Comments
Post a Comment