I’m trying to track down a bug where Kernel#select is returning [[],[],[]] as
opposed to [[anIO],[anIO],[anIO]] or nil. Why would it ever return [[],[],[]]?
Any hints would be greatly appreciated.
Thanks,
Wilkes
···
Do You Yahoo!?
Yahoo! - Official partner of 2002 FIFA World Cup
I’m trying to track down a bug where Kernel#select is returning
[,,] as opposed to [[anIO],[anIO],[anIO]] or nil. Why would it
ever return [,,]? Any hints would be greatly appreciated.
–
Dossy Shiobara mail: dossy@panoptic.com
Panoptic Computer Network web: http://www.panoptic.com/
“He realized the fastest way to change is to laugh at your own
folly – then you can let go and quickly move on.” (p. 70)
In message “Kernel#select questions” on 02/06/17, Wilkes Joiner boognish23@yahoo.com writes:
I’m trying to track down a bug where Kernel#select is returning [,,] as
opposed to [[anIO],[anIO],[anIO]] or nil. Why would it ever return [,,]?
Any hints would be greatly appreciated.
I don’t know. Maybe a bug. Show me more information, please.
Your platform, Ruby version (including date), reproducing (small)
code, etc.
I’m trying to track down a bug where Kernel#select is returning
[,,] as opposed to [[anIO],[anIO],[anIO]] or nil. Why would it
ever return [,,]? Any hints would be greatly appreciated.
I can think of a few off the top of my head:
Kernel#select timing out?
That should return nil, right?
Kernel#select receiving a signal (setting errno == EINTR perhaps).
I don’t know. Maybe a bug. Show me more information, please.
Your platform, Ruby version (including date), reproducing (small)
code, etc.
matz.
Win2K, Ruby 1.6.7 from Pragmatic Programmers
require ‘socket’
server = TCPServer.new(‘localhost’, 8088)
Thread.new { Thread.pass while true } # comment this line and it works
correctly
p select([server],nil, nil, 1) while true
At Mon, 17 Jun 2002 12:16:17 +0900, Wilkes Joiner wrote:
Win2K, Ruby 1.6.7 from Pragmatic Programmers
require ‘socket’
server = TCPServer.new(‘localhost’, 8088)
Thread.new { Thread.pass while true } # comment this line and it works
correctly
p select([server],nil, nil, 1) while true
I think I was wrong in [ruby-talk:40015] – although, I can’t
verify it now. On Linux, #select returns nil on timeout.
Maybe on Win32 it returns [, , ] … I can’t remember.
I just ran Wilkes’s test case on Linux, and #select returns
nil even with the Thread.new line not commented out.
I think the problem has to do with threading interfering with #select on Win32. [ruby-talk:40221] reminds me of this …
and the next message [ruby-talk:40279] you post a patch.
At Mon, 17 Jun 2002 12:16:17 +0900, > Wilkes Joiner wrote:
Win2K, Ruby 1.6.7 from Pragmatic Programmers
require ‘socket’
server = TCPServer.new(‘localhost’, 8088)
Thread.new { Thread.pass while true } # comment this line and it works
correctly
p select([server],nil, nil, 1) while true
I guess it’s [ruby-talk:40015].
–
Dossy Shiobara mail: dossy@panoptic.com
Panoptic Computer Network web: http://www.panoptic.com/
“He realized the fastest way to change is to laugh at your own
folly – then you can let go and quickly move on.” (p. 70)
I think I was wrong in [ruby-talk:40015] – although, I can’t
verify it now. On Linux, #select returns nil on timeout.
Maybe on Win32 it returns [, , ] … I can’t remember.
I just ran Wilkes’s test case on Linux, and #select returns
nil even with the Thread.new line not commented out.
For clarification, here is the sample output:
nil ← every second, due to timeout
nil
nil
[,,] ← when a request hits
[,,]
[,,]
[,,]
…
I think the problem has to do with threading interfering with #select on Win32. [ruby-talk:40221] reminds me of this …
and the next message [ruby-talk:40279] you post a patch.
I am trying to implement an iterator for a recursive structure. After too much
effort I got:
class Test
attr_accessor :name
attr_accessor :children
def initialize( name ) @children = [] @name = name
end
def each( block = nil, &syntax_block )
block ||= syntax_block
block.call( self, @children.length()) @children.each do |x|
x.each block
end
end
end
o = Test.new( “Foo”)
o.children << Test.new( “Bar”)
o.each do |x,y|
p x.name, y
end
This works OK, but… this does work as I expected:
def test()
o.each do |x,y|
p x.name, y
break if name == “Foo” # Should break, does not
return if name == “Foo” # Should return, does not
end
end
test()
Apparently “break” does not break (“return” does not return) unless some
"yield" is involved.
However I could not figure out how to rewrite Test##each() using yield.
What am I missing here ?
Thanks Guy, that works for me. I forgot about the last block parameter
being treated as a list if there is more actual actual parameters than
formal ones. Very convenient indeed. Thanks very much.
Jean-Hugues
···
At 01:22 18/06/2002 +0900, you wrote:
Well, I’ve not understood what you want to do but I’ll write something
like this
def each( block = nil, &syntax_block )
block ||= syntax_block
block.call( self, @children.length()) @children.each do |x|
x.each block
end
end
def each
yield self, @children.size @children.each do |x|
x.each do |y|
yield y
end
end
end