0
基本的には、Django mail_admins
を使って電子メールを受信したいと思っています。現在、私はポストの要求を処理する見解を持っており、それは以下のようになります。いずれかの例外が発生し、それが処理されないだとき Pythonスレッドで発生した例外をキャッチする方法。スレッドの実行?
import threading
# ...
def post(self, request, *args, **kwargs):
# Some stuff...
for message in entry['messaging']:
t = threading.Thread(
target=self.local_handler,
args=(message, page_id)
)
t.setDaemon(True)
t.start()
# Some more stuff
今、それはサーバログに表示されます。このようなもの:
Exception in thread Thread-2:
Traceback (most recent call last):
...
メールでこれらのトレースバックを受け取る方法はありますか? スレッドを使用する前にメールを受け取っていましたが、もう動作しません。
EDIT:ソリューションは、私のために働い似質問をlinnking彼の答えで提案イワン・miljkovic @として
。
import threading
from django.core.mail import mail_admins
# ...
def local_handler(self, message, page_id):
try:
# do stuff
except: # Any not handled exception will send an email with the traceback
import traceback
details = traceback.format_exc()
mail_admins('Backgrond execption happened', details)
def post(self, request, *args, **kwargs):
# Some stuff...
for message in entry['messaging']:
t = threading.Thread(
target=self.local_handler,
args=(message, page_id)
)
t.setDaemon(True)
t.start()
# Some more stuff
ニース、私はスレッドの呼び出し側以外で/試みを入れて、それが電子メールを送信しています。この質問を削除する必要があると思いますか?それは重複しているように見えるので、編集して例を追加してください。 –
この編集は大丈夫だと思います。 –