Python appengine任务在开发中工作,但在服务器上不工作

Python appengine任务在开发中工作,但在服务器上不工作,python,google-app-engine,Python,Google App Engine,我有一个后端为appengine的小应用程序。 我想合并数据库中的重复项并在taskqueue中执行: class MergeDuplicatesHandler(write_page.Handler): def get(self): self.render("mergeduplicateshandler.html") def post(self): adminpassword = self.request.g

我有一个后端为appengine的小应用程序。
我想合并数据库中的重复项并在taskqueue中执行:

    class MergeDuplicatesHandler(write_page.Handler):
        def get(self):
            self.render("mergeduplicateshandler.html")
        def post(self):
            adminpassword = self.request.get("adminpassword")
            if adminpassword == secret.ADMINPASSWORD:
                # Add the task to the default queue.
                taskqueue.add(url='/merge_duplicates', params={'adminpassword': adminpassword})

                self.redirect('/')
            else:
                self.response.out.write("Wrong password")

    class MergeDuplicates(write_page.Handler):
        def post(self):
            adminpassword = self.request.get("adminpassword")
            if adminpassword == secret.ADMINPASSWORD:
                 person_service.merge_duplicates()
write\u page.Handler
是一个webapp2处理程序

编辑:

这是我的merge_duplicates函数:

def merge_duplicates():
    people = get_all()
    peopletodelete = []
    count = 0
    for p1 in people:
        deleted = False
        if p1.cellphone != "" and p1.cellphone is not None:
            for pdel in peopletodelete:
                if(p1.key().id() == pdel.key().id()):
                    deleted = True
            if not deleted:
                p1people = get_people_by_cellphone(p1.cellphone)
                if p1people:
                    for p2 in p1people:
                        if(p1.key().id() != p2.key().id()):
                            p1 = merge_person(p1,p2)
                            try:
                                insert_or_update_person(p1.firstname,
                                                p1.secondfirstname,
                                                p1.lastname,
                                                p1.secondlastname,
                                                p1.cellphone,
                                                p1.shortcellphone,
                                                p1.workphone,
                                                p1.secondworkphone,
                                                p1.homephone,
                                                p1.email,
                                                p1.homenumber,
                                                p1.workernum,
                                                p1.username,
                                                p1.password)
                                peopletodelete.append(p2)
                            count = count + 1
                                # logging.info("Merge Dups Inserting: {0}".format(p1.firstname))
                            except UnicodeDecodeError:
                                logging.error("Problem with: {0} {1}".format(p1.firstname,p1.lastname))
        else:
                # logging.info("Merge Dups Deleting: {0}".format(p1.firstname))
                p1.delete()
    for pdel in peopletodelete:
        pdel.delete()
    return count

def merge_person(p1,p2):
    p1.firstname = merge_person_parameter(p1.firstname,p1.last_modified,p2.firstname,p2.last_modified)
    p1.secondfirstname = merge_person_parameter(p1.secondfirstname,p1.last_modified,p2.secondfirstname,p2.last_modified)
    p1.lastname = merge_person_parameter(p1.lastname,p1.last_modified,p2.lastname,p2.last_modified)
    p1.secondlastname = merge_person_parameter(p1.secondlastname,p1.last_modified,p2.secondlastname,p2.last_modified)
    p1.cellphone = merge_person_parameter(p1.cellphone,p1.last_modified,p2.cellphone,p2.last_modified)
    p1.shortcellphone = merge_person_parameter(p1.shortcellphone,p1.last_modified,p2.shortcellphone,p2.last_modified)
    p1.workphone = merge_person_parameter(p1.workphone,p1.last_modified,p2.workphone,p2.last_modified)
    p1.secondworkphone = merge_person_parameter(p1.secondworkphone,p1.last_modified,p2.secondworkphone,p2.last_modified)
    p1.homephone = merge_person_parameter(p1.homephone,p1.last_modified,p2.homephone,p2.last_modified)
    p1.email = merge_person_parameter(p1.email,p1.last_modified,p2.email,p2.last_modified)
    p1.homenumber = merge_person_parameter(p1.homenumber,p1.last_modified,p2.homenumber,p2.last_modified)
    p1.workernum = merge_person_parameter(p1.workernum,p1.last_modified,p2.workernum,p2.last_modified)
    p1.username = merge_person_parameter(p1.username,p1.last_modified,p2.username,p2.last_modified)
    p1.password =         merge_person_parameter(p1.password,p1.last_modified,p2.password,p2.last_modified)
    return p1


 def merge_person_parameter(param1,modified1,param2,modified2) :
    if not param1:
        if param2:
            param1 = param2
    if param1:
        if param2:
            if modified1 < modified2:
                param1 = param2
    return param1
def merge_duplicates():
people=get_all()
peopletodelete=[]
计数=0
对于人中的p1:
已删除=错误
如果p1.手机!=“”和p1。手机不是零:
对于peopletodelete中的pdel:
如果(p1.key().id()==pdel.key().id()):
已删除=真
如果未删除:
p1people=通过手机获取联系人(p1.手机)
如果有人:
对于p1中的p2:
如果(p1.key().id()!=p2.key().id()):
p1=合并人(p1,p2)
尝试:
插入或更新人员(p1.firstname,
p1.secondfirstname,
p1.lastname,
p1.secondlastname,
p1.手机,
p1.手机,
p1.工作电话,
p1.第二个工作电话,
p1.家庭电话,
p1.电子邮件,
p1.家庭号码,
p1.workernum,
p1.用户名,
p1.密码)
peopletodelete.append(p2)
计数=计数+1
#info(“合并DUP插入:{0}”。格式(p1.firstname))
除UNICEDECODEERROR外:
logging.error(“问题:{0}{1}.”格式(p1.firstname,p1.lastname))
其他:
#logging.info(“合并DUP删除:{0}”。格式(p1.firstname))
p1.删除()
对于peopletodelete中的pdel:
pdel.delete()
返回计数
def合并人员(p1、p2):
p1.firstname=合并人员参数(p1.firstname,p1.last\U MODIFED,p2.firstname,p2.last\U MODIFED)
p1.secondfirstname=合并人员参数(p1.secondfirstname,p1.last\u modified,p2.secondfirstname,p2.last\u modified)
p1.lastname=合并\人员\参数(p1.lastname,p1.last\修改,p2.lastname,p2.last\修改)
p1.secondlastname=合并\个人\参数(p1.secondlastname,p1.last\修改,p2.secondlastname,p2.last\修改)
p1.mobile=合并人员参数(p1.mobile,p1.last\u modified,p2.mobile,p2.last\u modified)
p1.shortcellphone=合并人员参数(p1.shortcellphone,p1.last\u modified,p2.shortcellphone,p2.last\u modified)
p1.workphone=合并人员参数(p1.workphone,p1.last\u modified,p2.workphone,p2.last\u modified)
p1.secondworkphone=合并人员参数(p1.secondworkphone,p1.last\u modified,p2.secondworkphone,p2.last\u modified)
p1.homephone=合并人员参数(p1.homephone,p1.last\u modified,p2.homephone,p2.last\u modified)
p1.email=合并人员参数(p1.email,p1.last\u modified,p2.email,p2.last\u modified)
p1.homenumber=合并人员参数(p1.homenumber,p1.last\u modified,p2.homenumber,p2.last\u modified)
p1.workernum=合并人员参数(p1.workernum,p1.last\u modified,p2.workernum,p2.last\u modified)
p1.username=合并人员参数(p1.username,p1.last\u modified,p2.username,p2.last\u modified)
p1.password=merge\u person\u参数(p1.password,p1.last\u modified,p2.password,p2.last\u modified)
返回p1
def merge_person_参数(参数1,修改后的1,参数2,修改后的2):
如果不是参数1:
如果参数2:
param1=param2
如果参数1:
如果参数2:
如果修改1<修改2:
param1=param2
返回参数1
所有这些在localhost上的开发中都非常有效。我把它上传到appengine。它运行任务,我看到它在运行,但什么也不做。
只是花了很长时间还是什么?

您可以将日志添加到流程中,并在开发人员控制台中检查应用程序引擎日志


我做了,但没有看到我放进去的所有日志。不过,我在日志中发现了一些东西:这个请求导致为应用程序启动一个新进程,从而导致首次加载应用程序代码。因此,与应用程序的典型请求相比,此请求可能需要更长的时间并使用更多的CPU。-您必须展开日志条目以查看所有日志。-“此请求可能需要更长的时间”意味着更长的一秒钟,而不是更多。您是否可以发布代码或描述您在person\u service.merge\u duplicates()中执行的操作?刚刚添加了merge\u duplicates函数,它在开发中工作得很好,但在AppEngineems上却没有任何作用,就像您试图通过迭代每个记录来修改数据存储一样,这在GAE上几乎总是一个坏主意,除非您有一个很小的数据集。这种任务更适合MapReduce:我将尝试MapReduce,谢谢