Advertisement
Guest User

Untitled

a guest
Jun 20th, 2019
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.87 KB | None | 0 0
  1. from threading import Thread
  2.  
  3. def send_async_email(msg):
  4. sleep(10)
  5. print('Sending message')
  6. mail.send(msg)
  7.  
  8. def send_email(subject, sender, recipients, text_body, html_body):
  9. msg = Message(subject, sender = sender, recipients = recipients)
  10. msg.body = text_body
  11. msg.html = html_body
  12. thr = Thread(target = send_async_email, args = [msg])
  13. thr.start()
  14.  
  15. async def send_async_mail(app, msg):
  16. with app.app_context():
  17. mail.send(msg)
  18.  
  19.  
  20. def send_mail(subject, sender, recipients, text_body, html_body):
  21. msg = Message(subject, sender=sender, recipients=recipients)
  22. msg.body = text_body
  23. msg.html = html_body
  24. mail.send(msg)
  25. send_async_mail(app, msg)
  26.  
  27. RuntimeWarning: coroutine 'send_async_mail' was never awaited send_async_mail(app, msg)
  28. RuntimeWarning: Enable tracemalloc to get the object allocation traceback
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement