My web app is written by python 2.7 & Django 1.11. When a customer pays to subscribe, it will immediately generate an invoice pdf and send to customer via email. But the code is not working when I cut time.sleep. i guess there is a racing condition.
The pdf file is generated with wkhtmltopdf (0.9.9) and pdfkit. What is the time required for sleep? or is it a suitable way?
I am going to send it to customer after pdf is generated. It needs to sleep again to wait for pdf generation?
output_html = current_month_folder + invoice_name + '.html'
output_filename = current_month_folder + invoice_name + '.pdf'
email_filename = invoice_name + '.pdf'
html_content = render_to_string(input_filename, context)
with open(output_html, 'w') as f:
f.write(html_content)
f.flush()
time.sleep(5)
pdfkit.from_file(output_html, output_filename)