From: Vasyl Smirnov Date: 2007-12-12T03:27:23+09:00 Subject: Re: Issue with threads and socket accept On Dec 11, 7:43 pm, Curt Sampson wrote: > Errr..."not investigating deep and strange mysteries of the Ruby interpreter > signal handling that are not comprehensible even after reading the source?" > > I hope I get a point for that answer. You probably do :) > But anyway, much as I'd like to know *why* the signal handling is set up > to ignore signals when waiting in accept(), a situation on which the > source code that does this is particularly silent, I just live with the > solution, which is: Well, actually the signal handler gets called, it calls shutdown, outputs a message to the stdout and closes the server socket. And the main thread is still inside accept. > Do a select() before your accept(), and wait until the socket in > question becomes readable. I've tried this, with the same success: def serve_mt2 until @servsock.closed? IO.select([@servsock]) clisock = @servsock.accept Thread.new(clisock) { |sock| work(sock) } end end