In WinXP ruby if I do this:
require 'socket’
server = TCPServer.new(‘localhost’, 8231)
server.accept
then while “server.accept” is running, Ctrl+C will not work to
terminate the program.
How can I make Ctrl+C work while server.accept is running? Do I have
to run server.accept in another thread?
Hi,
then while “server.accept” is running, Ctrl+C will not work to
terminate the program.
It’s one of restrictions on Windows version. Because interrupt
is implemented in user code, it’s dangerous while calling API
and libraries which don’t know about the interrupt.
How can I make Ctrl+C work while server.accept is running? Do I have
to run server.accept in another thread?
A work around is using “watcher” thread.
require ‘socket’
Thread.new {loop {sleep 0.01}} # <—
server = TCPServer.new(‘localhost’, 8231)
server.accept
···
At Thu, 10 Apr 2003 08:28:44 +0900, Philip Mak wrote:
–
Nobu Nakada