Open-uri used by threads cause uninitialized constant OpenURI::Net

e$B$3$s$K$A$O!#0KC#$H?=$7$^$9!#e(B

e$BJ#?t%9%l%C%I$Ge(B open-uri e$B$Ne(B open e$B$r;H$&$H!"e(B
uninitialized constant OpenURI::Net (NameError) e$B$K$J$j$^$9!#e(B

open-uri e$B$,%a%=%C%IFb$Ge(B net/http e$B$re(B require
e$B$7$F$$$k$N$,4X78$7$F$$$k$h$&$G$9$,!"e(B
e$B?<DI$$$G$-$F$$$^$;$s!#e(B
[email protected]$1$G$9$_$^$;$s!#e(B

ruby e$B$Oe(B $ ./configure --enable-shared --program-suffix=19
e$B$G:n$C$F$$$^$9!#e(B

$ cat test.rb
require ‘open-uri’
threads = (1…2).collect do
Thread.start do
open(‘http://www.google.com/’)
end
end
threads.each{|i|i.join}

$ ruby19 -v test.rb
ruby 1.9.0 (2007-10-11 patchlevel 0) [i686-linux]
/usr/local/lib/ruby/1.9/open-uri.rb:35: warning: method redefined;
discarding old open
/usr/local/lib/ruby/1.9/net/http.rb:1107: warning: instance variable
@sspi_enabled not initialized
/usr/local/lib/ruby/1.9/net/http.rb:1107: warning: instance variable
@sspi_enabled not initialized
/usr/local/lib/ruby/1.9/open-uri.rb:245:in open_http': uninitialized constant OpenURI::Net (NameError) from /usr/local/lib/ruby/1.9/open-uri.rb:709:inbuffer_open’
from /usr/local/lib/ruby/1.9/open-uri.rb:193:in block in open_loop' from /usr/local/lib/ruby/1.9/open-uri.rb:191:incatch’
from /usr/local/lib/ruby/1.9/open-uri.rb:191:in open_loop' from /usr/local/lib/ruby/1.9/open-uri.rb:137:inopen_uri’
from /usr/local/lib/ruby/1.9/open-uri.rb:611:in open' from /usr/local/lib/ruby/1.9/open-uri.rb:30:inopen’
from test.rb:5:in `block (2 levels) in ’

e$B?"ED$H?=$7$^$9!#e(B

e$B!!JX>hJs9p$G$9$,e(B…

Thu, 11 Oct 2007 16:46:29 +0900 e$B$N%a!<%k$K$F!"e(B
“Ken Date” [email protected] e$B$5$s$O=q$-$^$7$?e(B :

e$B$3$s$K$A$O!#0KC#$H?=$7$^$9!#e(B

e$BJ#?t%9%l%C%I$Ge(B open-uri e$B$Ne(B open e$B$r;H$&$H!"e(B
uninitialized constant OpenURI::Net (NameError) e$B$K$J$j$^$9!#e(B

e$B!!$A$g$&$I<+J,$,=q$$$F$$$k%W%m%0%i%$G$bF1$8LdBj$,=P$F$$$?$N$G$9$,!"<+J,e(B e$B$N%W%m%0%i%$KLdBj$,$"$k$N$+$H;W$C$F$$$^$7$?!#e(B

e$B!!0KC#$5$s$Ne(B test.rb e$B$re(B 1.8.6
e$B4D6-$G<B9T$7$?$H$3$m!"F1$8%(%i!<$,=P$^$7$?!#e(B

[email protected][~ ]ruby -v
ruby 1.8.6 (2007-03-13 patchlevel 0) [i386-freebsd6]
[email protected][~ ]ruby test.rb
/usr/local/lib/ruby/1.8/open-uri.rb:212:in open_http': uninitialized constant OpenURI::Net (NameError) from test.rb:7:injoin’
from test.rb:7
from test.rb:7:in `each’
from test.rb:7

e$B!!e(Bruby e$B$Oe(B FreeBSD e$B$Ne(B ports
e$B$+$iF~$l$F$$$^$9!#[email protected];d$N4D6-$G$O>e5-%(%i!<e(B
e$B$,=P$k>l9g$H=P$J$$>l9g$,$"$j!">o$K%(%i!<$K$J$k$o$1$G$O$"$j$^$;$s!#e(B

e$B%9%l%C%[email protected]$+$i$G$7$g$&$+!)e(B

e$B$J$<!$N$h$&$Ke(B net/http [email protected]<(E$Ke(B require
e$B$9$k$H%(%i!<$,=P$J$/$J$j$^$9!#e(B

— test.rb.orig 2007-10-12 09:15:29.000000000 +0900
+++ test.rb 2007-10-12 09:14:50.000000000 +0900
@@ -1,4 +1,5 @@
require ‘open-uri’
+require ‘net/http’

threads = (1…9).collect do
Thread.start do

e$B0J>e$G$9!#e(B

In article
[email protected],
“Ken Date” [email protected] writes:

e$BJ#?t%9%l%C%I$Ge(B open-uri e$B$Ne(B open e$B$r;H$&$H!"e(B
uninitialized constant OpenURI::Net (NameError) e$B$K$J$j$^$9!#e(B

open-uri e$B$,%a%=%C%IFb$Ge(B net/http e$B$re(B require e$B$7$F$$$k$N$,4X78$7$F$$$k$h$&$G$9$,!"e(B
e$B?<DI$$$G$-$F$$$^$;$s!#e(B
[email protected]$1$G$9$_$^$;$s!#e(B

e$BC1=c2=$7$F$_$^$7$?!#e(B

% cat t.rb
sleep 0.1
module M
end
% ./ruby -ve ’
(1…2).map {|i|
Thread.start {
require “t”
p [i, M]
}
}.map {|t| t.join }

ruby 1.9.0 (2007-10-13 patchlevel 0) [i686-linux]
[1, M]
-e:5:in `block (2 levels) in ': uninitialized constant M
(NameError)

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs