Kernel#select questions


(Wilkes Joiner) #1

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


(Dossy) #2

I can think of a few off the top of my head:

  1. Kernel#select timing out?

  2. Kernel#select receiving a signal (setting errno == EINTR perhaps).

– Dossy

···

On 2002.06.17, Wilkes Joiner boognish23@yahoo.com wrote:

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)


(Yukihiro Matsumoto) #3

Hi,

···

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.

						matz.

(Wilkes Joiner) #4

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:

  1. Kernel#select timing out?

That should return nil, right?

  1. Kernel#select receiving a signal (setting errno == EINTR perhaps).

Would this generate an exception?

  • Wilkes
···

— Dossy dossy@panoptic.com wrote:

On 2002.06.17, Wilkes Joiner boognish23@yahoo.com wrote:


Do You Yahoo!?
Yahoo! - Official partner of 2002 FIFA World Cup


(Wilkes Joiner) #5

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

···

Do You Yahoo!?
Yahoo! - Official partner of 2002 FIFA World Cup


(Nobuyoshi Nakada) #6

Hi,

···

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].


Nobu Nakada


(Dossy) #7

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.

– Dossy

···

On 2002.06.17, nobu.nokada@softhome.net nobu.nokada@softhome.net wrote:

Hi,

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)


(Wilkes Joiner) #8

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.

That seems to be the problem. It behaves correctly using ruby 1.7.2 from
http://www.dm4lab.to/~usa/ruby/index_en.html.

Thanks to everyone for helping me out.

-Wilkes

···

Do You Yahoo!?
Yahoo! - Official partner of 2002 FIFA World Cup


(Jean-Hugues ROBERT) #9

Hello,

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,

Jean-Hugues


(ts) #10

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

Guy Decoux


(Nikodemus Siivola) #11

Not quite sure what you are doing, but x.name is not the same as name.

Either:

break if x.name == "Foo"
return if x.name == "Foo"
or

name = x.name
break if …

– Nikodemus

···

On Tue, 18 Jun 2002, Jean-Hugues ROBERT wrote:

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


(Jean-Hugues ROBERT) #12

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

Guy Decoux


Web: http://hdl.handle.net/1030.37/1.1
Phone: +33 (0) 4 92 27 74 17