我正在运行python龙卷风服务器,我正在尝试在我的网站上创建pdf报告。我写的处理这个的功能如下:
def __generate_pdf(self, list_params):
result = []
try:
try:
print "Deleting old report PDF..."
os.remove('report.pdf')
except Exception as e:
pass
options = {
'load-error-handling': 'ignore',
'page-width': str(list_params[8]) + 'in',
'page-height': str(list_params[9]) + 'in'
}
report_url = 'http://127.0.0.1/report.html'
for i in range(1, 10):
report_url += {True: '?', False: '&'}[i == 1]
report_url += 'p' + str(i) + '=' + {True: '', False: str(list_params[i])}[list_params[i] is None]
print "Generating PDF of: " + report_url
print "Command: pdfkit.from_url(url='"+ report_url +"', output_path='report.pdf', options="+ str(options) +")"
result.append(report_url)
if pdfkit.from_url(url=report_url, output_path='report.pdf', options=options):
return result
else:
self.errors = True
print 'Failed to create PDF'
self.message = 'Failed to create PDF'
return result
except Exception as e:
self.errors = True
print 'Failed to create PDF, ' + str(e)
self.message = 'Failed to create PDF, ' + str(e)
return result
我遇到的问题是Tornado似乎在执行pdfkit.from_url()命令时锁定...我正在使用AJAX请求来启动此功能,浏览器永远不会收到来自服务器的响应一旦发出AJAX请求,服务器将不会响应任何其他请求。我99%肯定它与命令本身无关,因为我可以将打印到控制台的命令复制/粘贴到服务器上的python终端中,并且执行得很好。