问题
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