据我了解,您正在执行以下操作:
for i in range(0,100):
ent = My_Entity() # create and save entity
db.put(ent)
ent = db.get(ent.key()) # get, modify and save the entity
ent.property = 'foo'
db.put(ent)
ent.get(ent.key()) # get and delete the entity
db.delete(my_ent)
进行一些错误检查以确保您有要删除、修改的实体,并且您在查找要删除或修改的实体时遇到了一堆错误。正如您所说,这是因为不能保证调用按顺序执行。
但是,我想了解如何处理这种使用实体进行并发操作的情况。
最好的办法是批量处理您为持久化实体所做的任何修改。例如,如果您要创建/保存/修改/保存或修改/保存/删除,请尽可能尝试组合这些步骤(即创建/修改/保存或修改/删除)。这不仅可以避免您看到的错误,还可以减少您的 RPC。遵循此策略,上述循环将减少为...
prop = None
for i in range(0,100):
prop = 'foo'
换句话说,对于任何需要快速设置/删除的东西,只需使用局部变量。这就是 GAE 为您提供的答案。在您弄清楚所有快速的东西之后,您无法将该信息保留在实体中。
Other than that there isn't much you can do. Transactions can help you if you need to make sure a bunch of entities are updated together but won't help if you're trying to multiple things to one entity at once.
EDIT: You could also look at the pipelines API.