Appengine:put_async 不起作用(至少在开发服务器中)?
注意: 它在生产中确实有效。我的意思是,当我上传应用程序时,它运行得很好。问题出在开发服务器上。
这里有一些代码可以向您展示我正在尝试做什么:
e = Employee(key_name = 'some_key_name',name='John Bonham')
db.put_async(e)
如果我这样做,并且在一段时间后我尝试得到它,
e = Employee.get_by_key_name('some_key_name') # e is None
它不起作用。 e 没有!但是,如果我这样做:
e = Employee(key_name = 'some_key_name',name='John Bonham')
op = db.put_async(e)
op.get_result()
效果很好。
我缺少什么?
重要提示:我等待一段时间来检查对象是否已创建!我在调用 put_async 后没有得到。但是,一分钟后,它仍然不起作用。我在开发服务器中!
NOTE:
IT DOES WORK IN PRODUCTION. I MEAN, WHEN I UPLOAD THE APPLICATION IT JUST WORKS FINE. THE PROBLEM IS IN THE DEVELOPMENT SERVER.
Here is some code that can show you what i'm trying to do:
e = Employee(key_name = 'some_key_name',name='John Bonham')
db.put_async(e)
If i do it, and after some time i try to get it
e = Employee.get_by_key_name('some_key_name') # e is None
It doesn't work. e is None! But, if i do this:
e = Employee(key_name = 'some_key_name',name='John Bonham')
op = db.put_async(e)
op.get_result()
It works fine.
What am i missing?
Important Note: I wait some time to check if the object is created! I don't do get after the call put_async. But, it still doesn't work, even a minute after. I'm in the Development Server!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果您不在 RPC 上调用
.wait()
或.get_result()
,则无法保证它已完成。对于非多线程的 dev_appserver 来说,实际工作是在调用这些方法时完成的 - 它实际上在开发中并不是异步的,仅在生产中是异步的。If you don't call
.wait()
or.get_result()
on an RPC, there is no way to guarantee it's completed. In the case of thedev_appserver
, which is not multi-threaded, the actual work is done when you call those methods - it's not actually asynchronous in development, only in production.