# The ruby way of interrupting a Kernel::select?

**URL:** <https://www.ruby-forum.com/t/the-ruby-way-of-interrupting-a-kernel-select/53619>\
**Category:** Ruby\
**Created:** [February 11, 2006, 11:37pm UTC](https://www.ruby-forum.com/t/the-ruby-way-of-interrupting-a-kernel-select/53619 "2006-02-11T23:37:16Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Christoffer\_LernSSS](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/da6949/32.png) [@Christoffer\_LernSSS](https://www.ruby-forum.com/u/Christoffer_LernSSS)\
**Post date:** [February 11, 2006, 11:37pm UTC](https://www.ruby-forum.com/t/the-ruby-way-of-interrupting-a-kernel-select/53619/1 "2006-02-11T23:37:16Z")

</div>

Hello everyone,

As a newbie with too much java-experience, I found it strange that I  
couldn’t interrupt the Kernel::select.

Basically what I wanted to do would be to interrupt the select as  
soon as a socket decided it wanted to write something, and then add  
that channel to the write-interest array.

I found no obvious way of doing that, so I made a hack around it: I  
registered a pipe with the read-interest and every time I wanted to  
write something then I would send a single byte on the pipe, which  
would interrupt the select and allow me to register the socket with  
the array.

I.e. something like this:

8\<-------------

```
@notifier, @requester = IO.pipe # this is my hack
	puts "Server started on port #{port} with handler #{@delegate}."
	while (true)
		@read = [@server, @notifier]
		@write = Array.new
		@error = [@server]
		@connections.each do |connection|
			@read << connection.io if connection.read
			@write << connection.io if connection.write
			@error << connection.io if connection.read
		end
		read, write, error = Kernel::select(@read, @write, @error)
		@connections.each do |connection|
			connection.handle_read if read.include? connection.io
			connection.handle_write if write.include? connection.io
			connection.handle_error if error.include? connection.io
		end
		@notifier.getc if read.include? @notifier
		handle_connect if read.include? @server
	end

```

8\<------------------

```
def poke
	#this is a hack to interrupt Kernel::select
	puts "Poking!"
	@requester.putc "!"
end

```

8\<------------------

Please tell me there’s a better way! 🙂

/Christoffer
