ruby - Why the exit function doesn't actually terminate the program -
why second thread doesn't terminate program , application still waits input first thread?
curses.init_screen first = thread.new loop { curses.getch } end second = thread.new curses.close_screen exit end second.join first.join
os -- windows 8.
ruby 2.0.0p481 (2014-05-08) [x64-mingw32]
thanks in advance.
i think exit
in scope running thread#exit
instead of kernel#exit
(as expecting). i'm using ruby 2.1.2, however, perhaps behavior bit different.
you can see running code:
2.1.0 :007 > thread.new 2.1.0 :008 > puts self.inspect 2.1.0 :009?> end main => #<thread:0x0000010142b8f8 sleep>
as opposed to, if run puts self.inspect
on own (not inside thread):
2.1.0 :011 > puts self.inspect main => nil
you should killed process if, instead, explicitly call kernel#exit
2.1.0 :001 > thread.new 2.1.0 :002 > kernel::exit 2.1.0 :003?> end
...which, in irb
, close interactive session (kill process).
a simple example
if put in file:
# test.rb first = thread.new while 4 != 5 puts gets end end second = thread.new kernel::exit end second.join first.join
...and command line:
$ ruby test.rb
...the program close, not giving me time provide input first
thread's gets
method call.
whereas, if replace kernel::exit
call thread::exit
, program never exit, continually prompt me input.
possibly difference between 2.0.0p481
opposed 2.1.2 [x86_64]
?
Comments
Post a Comment