首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >应用程序引擎:调试和运行不同(神秘)

应用程序引擎:调试和运行不同(神秘)
EN

Stack Overflow用户
提问于 2015-10-14 22:05:50
回答 1查看 20关注 0票数 0

我正在构建一个wiki,当调试期间的结果似乎与程序运行期间的结果不同时,我遇到了一个问题。

代码语言:javascript
复制
class WikiPage(Handler):
    def get(self, id):
            id, existing_article, article_content = self.get_stripped_id_article_content(id)
            logging.error(("GET! id: {0}; article: {1}; content: {2}").format(id, existing_article, article_content))
            <...>

    def strip_id(self, id):
            id = id.replace("/", "")
            return id

    def get_stripped_id_article_content(self, id):
        id = self.strip_id(id)
        q = Article.all()
        q.filter("id = ", id)
        existing_article = q.get()

        content = existing_article.content if existing_article else ""

        return id, existing_article, content
    <...>

class CreateEditPage(WikiPage):
    def post(self, id):
        id, existing_article, article_content = self.get_stripped_id_article_content(id)
        user = self.get_user(self.request)

        input_content = self.request.get("content")

        if existing_article:
            existing_article.content = input_content
            existing_article.put()

        else:            
            new_article = Article(id = id, content = input_content)
            new_article.put()
            id, existing_article, article_content = self.get_stripped_id_article_content(id)
            logging.error(("POST! In Else. id: {0}; article: {1}; content: {2}").format(id, existing_article, article_content))



        id, existing_article, article_content = self.get_stripped_id_article_content(id)
        logging.error(("POST! Outside Else. id: {0}; article: {1}; content: {2}").format(id, existing_article, article_content))
        self.redirect("/" + str(id))

PAGE_RE = r'(/(?:[a-zA-Z0-9_-]+/?)*)'
app = webapp2.WSGIApplication([('/_edit' + PAGE_RE, CreateEditPage),
                               (PAGE_RE, WikiPage),
                               ],
                              debug=True)

首先,我清除了数据库中的所有内容,并清除了memcache。

我运行我的申请:

代码语言:javascript
复制
INFO     2015-10-14 21:06:52,744 sdk_update_checker.py:229] Checking for updates to the SDK.
INFO     2015-10-14 21:06:53,135 api_server.py:205] Starting API server at: http://localhost:53588
INFO     2015-10-14 21:06:53,141 dispatcher.py:197] Starting module "default" running at: http://localhost:8080
INFO     2015-10-14 21:06:53,142 admin_server.py:118] Starting admin server at: http://localhost:8000
ERROR    2015-10-14 21:10:10,804 gmv_wiki.py:194] GET! id: ; article: None; content: 
INFO     2015-10-14 21:10:10,810 module.py:809] default: "GET / HTTP/1.1" 302 -
INFO     2015-10-14 21:10:10,847 module.py:809] default: "GET /_edit/ HTTP/1.1" 200 348
ERROR    2015-10-14 21:10:12,228 gmv_wiki.py:194] GET! id: newpost; article: None; content: 
INFO     2015-10-14 21:10:12,239 module.py:809] default: "GET /newpost HTTP/1.1" 302 -
INFO     2015-10-14 21:10:12,264 module.py:809] default: "GET /_edit/newpost HTTP/1.1" 200 348
ERROR    2015-10-14 21:10:18,945 gmv_wiki.py:194] GET! id: new_article; article: None; content: 
INFO     2015-10-14 21:10:18,951 module.py:809] default: "GET /new_article HTTP/1.1" 302 -
INFO     2015-10-14 21:10:18,976 module.py:809] default: "GET /_edit/new_article HTTP/1.1" 200 348
ERROR    2015-10-14 21:10:50,979 gmv_wiki.py:246] POST! In Else. id: new_article; article: None; content: 
ERROR    2015-10-14 21:10:50,985 gmv_wiki.py:251] POST! Outside Else. id: new_article; article: None; content: 
INFO     2015-10-14 21:10:50,991 module.py:809] default: "POST /_edit/new_article HTTP/1.1" 302 -
ERROR    2015-10-14 21:10:51,014 gmv_wiki.py:194] GET! id: new_article; article: None; content: 
INFO     2015-10-14 21:10:51,022 module.py:809] default: "GET /new_article HTTP/1.1" 302 -
INFO     2015-10-14 21:10:51,051 module.py:809] default: "GET /_edit/new_article HTTP/1.1" 200 348
ERROR    2015-10-14 21:11:18,321 gmv_wiki.py:251] POST! Outside Else. id: new_article; article: <gmv_wiki.Article object at 0x7f684d2ba250>; content: New article content.
INFO     2015-10-14 21:11:18,326 module.py:809] default: "POST /_edit/new_article HTTP/1.1" 302 -
ERROR    2015-10-14 21:11:18,351 gmv_wiki.py:194] GET! id: new_article; article: <gmv_wiki.Article object at 0x7f684d2663d0>; content: New article content.
INFO     2015-10-14 21:11:18,358 module.py:809] default: "GET /new_article HTTP/1.1" 200 262

我调试我的应用程序:

代码语言:javascript
复制
pydev debugger: starting (pid: 10230)
INFO     2015-10-14 21:12:24,730 sdk_update_checker.py:229] Checking for updates to the SDK.
INFO     2015-10-14 21:12:25,435 api_server.py:205] Starting API server at: http://localhost:44302
INFO     2015-10-14 21:12:25,463 dispatcher.py:197] Starting module "default" running at: http://localhost:8080
INFO     2015-10-14 21:12:25,467 admin_server.py:118] Starting admin server at: http://localhost:8000
pydev debugger: starting (pid: 10250)
ERROR    2015-10-14 21:12:36,523 gmv_wiki.py:194] GET! id: new_article_1; article: None; content: 
INFO     2015-10-14 21:12:36,547 module.py:809] default: "GET /new_article_1 HTTP/1.1" 302 -
INFO     2015-10-14 21:12:36,766 module.py:809] default: "GET /_edit/new_article_1 HTTP/1.1" 200 348
ERROR    2015-10-14 21:12:54,394 gmv_wiki.py:246] POST! In Else. id: new_article_1; article: None; content: 
ERROR    2015-10-14 21:12:54,430 gmv_wiki.py:251] POST! Outside Else. id: new_article_1; article: None; content: 
INFO     2015-10-14 21:12:54,452 module.py:809] default: "POST /_edit/new_article_1 HTTP/1.1" 302 -
ERROR    2015-10-14 21:12:54,587 gmv_wiki.py:194] GET! id: new_article_1; article: <gmv_wiki.Article object at 0x7fad181bef10>; content: New article 1 content.
INFO     2015-10-14 21:12:54,610 module.py:809] default: "GET /new_article_1 HTTP/1.1" 200 266

您能看看代码中logging.error的情况吗?以及日志中的结果。

两种绝对平等的情况。文章 #普通运行1 #调试

该程序的行为如下: 1.在调试过程中一切正常:为一篇新文章创建编辑表单,当我按下"Submit“键时,内容被放置到数据库中,并被重定向到该文章的wiki页面。2.当我只运行程序(而不是调试程序)时,打开一篇新文章的编辑表单,输入一些内容并按下"Submit“。然后我被重定向到wiki页面。在那个地址找不到wiki页面。我被重定向到编辑页面。然后,当我再次输入内容时,内容最终被放入数据库,wiki页面就会打开。

对我来说,谜团是: 1.为什么运行和调试之间有区别? 2.为什么在我完成new_article.put()之后,在post函数中仍然找不到文章对象? 3。然后我被重定向到wiki页面,不知怎么找到了文章对象。真奇怪。4.为什么existing_article.put()工作得很好,而new_article.put()不向数据库放置任何东西?

好吧,我好像是在胡思乱想。你能帮我解决这些问题吗?谢谢你的建议。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2015-10-14 22:47:03

我怀疑您正在遇到GAE数据存储最终一致性问题。基本上,在new_article.put()中保存的一篇新文章在Article.all()查询中(通常是短)中找不到。您仍然可以通过id、tho访问它,但是您必须为此调整代码。

我怀疑行为上的差异是因为调试模式执行的总体速度较低,这可能隐藏最终的一致性问题。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/33136420

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档