From: Eric Wong Date: 2013-12-08T06:49:18+00:00 Subject: [ruby-core:58961] Re: [ruby-trunk - Feature #5446] at_fork callback API Tanaka Akira wrote: > 2013/12/7 Eric Wong : > > However, I want to do this via callback, example with Worker class: > > > > class Worker > > attr_writer :pid > > > > def initialize > > @r, @w = IO.pipe > > Process.atfork_parent { @r.close unless @r.closed? } > > Process.atfork_child { @w.close unless @w.closed? } > > end > > end > > > > worker = Worker.new # IO.pipe > > worker.pid = fork { ... } > > ... > > > > # No need to remember what to close in parent/child > > I think it doesn't work with multiple thread. True, but I wasn't intending this example to be used for an MT application, but a single-threaded, multi-process HTTP server. Generally, I do not use fork after I've spawned threads (unless followed immediately with exec).