我将 GAE 上的应用程序从 Python 2.5 迁移到 Python 2.7。
Python 2.7 允许线程,我正在尝试创建一个线程以在后台发送电子邮件。这里的线程:
from google.appengine.api import background_thread
from django.core.mail import send_mail
subject = 'Hello!'
msg = '\n \n Hello World!'
sender = settings.DEFAULT_FROM_EMAIL
to = 'xx@xx.com'
t = background_thread.BackgroundThread(target=send_mail, args=[subject, msg, sender, to])
t.start()
它应该可以在 GAE 上运行,但是在我上传应用程序并尝试执行后,出现以下错误:
Django Version: 1.3.1
Exception Type: FrontendsNotSupported
Exception Location: /python27_runtime/python27_lib/versions/1/google/appengine/api/background_thread/background_thread.py in start_new_background_thread, line 84
Python Executable: /python27_runtime/python27_dist/python
Python Version: 2.7.3
有谁知道为什么会出现这个错误?
使用普通线程的代码:
from threading import Thread
from django.core.mail import send_mail
subject = 'Hello!'
msg = '\n \n Hello World!'
sender = settings.DEFAULT_FROM_EMAIL
to = 'xx@xx.com
t = Thread(target=send_mail, args=[subject, msg, sender, to], kwargs={'fail_silently': False})
t.setDaemon(True)
t.start()