jruby IO.popen read hangs in action when requests are made to the local dev server

大城市里の小女人 提交于 2019-12-25 04:06:47

问题


I just want to send the output of wkhtmltopdf to the user. It shouldn't be so hard.

def it
    send_pdf "file.pdf"
end

def send_pdf(file)
  url= url_for(params) # Example: http://localhost:3000/report/it
  webkit= Rails.root.join('app', 'bin', 'wkhtmltopdf', 'current')
  cmd= "#{webkit} -q \"#{url_for(params)}\" -"

  data= IO.popen(cmd).read ############### HANGS HERE ###################

  send_data(data, type: "application/pdf", filename: file)
end

Why does it hang and how to fix it?


回答1:


I think the clue here may be it's a local development server - so maybe it can only accept one request at a time.

To test, try getting the html from somewhere else:

def send_pdf(file)
  # [...]
  cmd= "#{webkit} -q http://brighterplanet.com -"
  # [...]
end

If that works, then the answer to your question is that the development server is "single-threaded".



来源:https://stackoverflow.com/questions/10834556/jruby-io-popen-read-hangs-in-action-when-requests-are-made-to-the-local-dev-serv

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!