[ruby-list:50484] [質問] Thread.stop が無い?
From:
<yamataka@...08.itscom.net>
Date:
2017-02-16 08:35:46 UTC
List:
ruby-list #50484
山口と申します。
yama@ROSWELL:/tmp$ uname -a
CYGWIN_NT-6.1 ROSWELL 2.5.2(0.297/5/3) 2016-06-23 14:29 x86_64 Cygwin
yama@ROSWELL:/tmp$ ruby --version
ruby 2.2.5p319 (2016-04-26 revision 54774) [x86_64-cygwin]
の環境で、
下記の Threadを用いたスクリプトにおいて、
yama@ROSWELL:/tmp$ cat -n thread.rb
1 #! /usr/bin/env ruby
2
3 require 'pp'
4
5 ssdp = Thread.new {
6 puts "In ssdp thread"
7 }
8
9 loop do
10 puts "In main thread"
11 sleep(5)
12 ssdp.stop
13 sleep(5)
14 ssdp.run
15 end
16
yama@ROSWELL:/tmp$ ./thread.rb
In main thread
In ssdp thread
./thread.rb:12:in `block in <main>': undefined method `stop' for #<
Thread:0x00000600486ec0@./thread.rb:5 dead> (NoMethodError)
from ./thread.rb:9:in `loop'
from ./thread.rb:9:in `<main>'
実行すると、stopメソッドが無いとの事でエラーになってしまいます。
https://docs.ruby-lang.org/ja/2.2.0/class/Thread.html
を参照すると、stop メソッドがある様なのですが…
pp ssdp.methods で method を出力させてみましたが、stop method が有りませ
ん。
何か勘違いをしているか、ご教示お願いできますでしょうか?
[:pending_interrupt?,
:raise,
:join,
:value,
:kill,
:terminate,
:exit,
:run,
:wakeup,
…
:priority,
:priority=,
:status,
:thread_variable_get,
:thread_variable_set,
:thread_variables,
:thread_variable?,