我通过Elastic Beanstalk在AWS上运行了一个CherryPy应用程序,其中一项工作是检查Gmail收件箱中的新邮件,如下所示:
编辑:
# snippet of the code responsible for starting the poller in question
# application.py
def __init__(self):
...
# register callbacks with monitor (token access check, history feed poller)
credentials_checker = Monitor(cherrypy.engine, self.check_access_token, frequency=30)
mail_checker = Monitor(cherrypy.engine, self.mail_processor.safe_poll_history_feed, frequency=10)
credentials_checker.subscribe()
mail_checker.subscribe()
# mail_checker.py
def safe_poll_history_feed(self):
try:
self.poll_history_feed()
except:
# no restart needed
cherrypy.log("Exception in poll_history_feed()!", traceback=True)
def poll_history_feed(self):
new_messages = self.mail_service.users().messages().list(userId="me", labelIds=["INBOX", "UNREAD"]).execute()
result_size = int(new_messages["resultSizeEstimate"])
cherrypy.log("Checking for new messages...")
if result_size > 0:
# process message
cherrypy.log("number of new messages: %s" % result_size)
cherrypy.log("New messages! Processing...")
for x in new_messages["messages"]:
self.process_email(x["id"])
else:
cherrypy.log("No new messages.")
return
但问题是,似乎负责进行实际检查的线程似乎被某些东西杀死了,我无法弄清楚是什么。下面的日志片段:
[14/Mar/2016:15:32:55] Checking for new messages...
[14/Mar/2016:15:32:55] No new messages.
[14/Mar/2016:15:33:05] Checking for new messages...
[14/Mar/2016:15:33:05] No new messages.
[14/Mar/2016:15:33:15] Checking for new messages...
[14/Mar/2016:15:33:15] No new messages.
[14/Mar/2016:15:33:17] Checking access token.
[14/Mar/2016:15:33:17] Access token still good. Continuing...
[14/Mar/2016:15:33:26] Checking for new messages...
[14/Mar/2016:15:33:26] No new messages.
[14/Mar/2016:15:33:32] ENGINE Keyboard Interrupt: shutting down bus
[14/Mar/2016:15:33:32] ENGINE Bus STOPPING
[14/Mar/2016:15:33:32] ENGINE HTTP Server cherrypy._cpwsgi_server.CPWSGIServer(('127.0.0.1', 8080)) shut down
[14/Mar/2016:15:33:32] ENGINE Stopped thread 'Monitor'.
[14/Mar/2016:15:33:32] ENGINE Stopped thread 'Autoreloader'.
[14/Mar/2016:15:33:32] ENGINE Stopped thread 'Monitor'.
[14/Mar/2016:15:33:32] ENGINE Stopped thread '_TimeoutMonitor'.
[14/Mar/2016:15:33:32] ENGINE Bus STOPPED
[14/Mar/2016:15:33:32] ENGINE Bus EXITING
[14/Mar/2016:15:33:32] ENGINE Bus EXITED
[14/Mar/2016:15:33:32] ENGINE Waiting for child threads to terminate...
# note: the server seems to be responding to outside requests judging by this line and the ones following it.
[16/Mar/2016:04:48:41] Sent internal chat notification to user@userdomain.com, subject [MENTIONED] Client Portal
...SNIP
该应用程序的其余部分似乎保持不变,因为它响应请求就好了,但它完全停止检查新邮件。重新启动应用服务器只能暂时修复它(不到10分钟左右)。我已经检查过,我可以考虑检查一下,但是在这个过程被杀的时候我还没有看到其他任何事情发生。
自从问题首次发布以来,我已经增加了实例类型的大小,只是为了看看是否能解决这个问题(它没有做到)。我想我可能在某些时候搞砸了日志,因为我不再在日志中看到来自CherryPy的ENGINE消息,所以我现在正在努力解决这个问题。
可能导致这种情况的原因,我该如何解决?我猜测它可能检查邮件的频率有点太快了?