在脚本完成之前使用Ruby CGI返回响应?

任何人都知道如何在CGI脚本执行完之前在Ruby中发送CGI响应?

我正在创建一个即发即弃的HTTP API。 我希望客户端通过HTTP将数据推送给我并使响应成功返回, 然后它调整数据并进行一些处理(客户端不必等待响应)。

我尝试了几件不起作用的东西,包括fork。 通过HTTP调用时,以下将等待5秒。

#!/usr/bin/ruby require 'cgi' cgi = CGI.new cgi.out "text/plain" do "1" end pid = fork if pid # parent Process.detach pid else # child sleep 5 end 

我回答了自己的问题。 结果我只需要在子进程中关闭$ stdin,$ stdout和$ stderr:

 #!/usr/bin/ruby require 'cgi' cgi = CGI.new cgi.out "text/plain" do "1" end pid = fork if pid # parent Process.detach pid else # child $stdin.close $stdout.close $stderr.close sleep 5 end