简体   繁体   English

Google App Engine(Python 2.7)中的APScheduler问题

[英]Problems with APScheduler in Google App Engine(Python 2.7)

I am new to Google App Engine. 我是Google App Engine的新手。 The APScheduler works perfectly fine for a simple code in python. 对于Python中的简单代码,APScheduler可以很好地工作。 But when uploaded to the GAE, it shows continuous loading with no response. 但是,当上传到GAE时,它显示连续加载而没有响应。

import webapp2
import sys
import time
def my_job(text):
    self.response.out.write(text)

sys.path.insert(0, 'libs')

from bs4 import BeautifulSoup
from apscheduler.scheduler import Scheduler
sched = Scheduler()

class MainPage(webapp2.RequestHandler):
    def get(self):
    html = "<html><p>Para 1<p>Para 2<blockquote>Quote 1<blockquote>Quote 2"
soup = BeautifulSoup(html)
self.response.out.write(soup.prettify())
self.response.out.write(time.strftime("%d/%m/%Y"))
self.response.out.write(time.strftime("%H:%M:%S"))

job = sched.add_date_job(my_job, '2015-03-5 16:13:05', ['Hello World'])#
sched.start()
while True:
  sleep(1)
app = webapp2.WSGIApplication([('/', MainPage)], debug=True)

As the other person pointed out the while true: sleep will cause you problems. 正如另一个人指出的那样,事实是:睡眠会给您带来麻烦。 However your problems go deeper than that. 但是,您的问题要深得多。

APScheduler is not an appropriate tool for appengine out of the box, unless you are running it under compute engine. APScheduler不是开箱即用的合适引擎工具,除非您在计算引擎下运行它。

Appengine front end requests can only run for a max of 60 seconds. Appengine前端请求最多只能运行60秒。 Appengine has it's own facility called task queues and cron. Appengine有自己的工具,称为任务队列和cron。

APScheduler would need to be modified to use these underlying services to be of any use on appengine. 需要对APScheduler进行修改,以使用这些基础服务来对appengine产生任何作用。

The problem in your code is: 您的代码中的问题是:

while True:
  sleep(1)

This will cause your request to hang forever and never respond. 这将使您的请求永远挂起,并且永远不会响应。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM