jeudi 3 juillet 2014

App Engine Python27 SDK - NDB Query.iter() QueryIterator returns "Deadlock waiting for, pending" error


Vote count:

0




Since I am using NDB for my projects, on Python 2.7 SDK, I cannot use Query().iter() normally with Jinja2 templates.


My usual code follows this pattern:



mc_key = ...
instances = memcache.get('instances-%s' % mc_key)
if not instances:
q_i = MyModel.query(...)
instances = q_i.iter()
if instances:
memcache.set('instances-%s' % mc_key, instances)


And then in Jinja2:



{% for i in instances %}
{{i.property1}}
{% endfor %}


This also happens when I call the QueryIterator object in the Python code. Adding to the previous Python code:



for i in instances:
# Do something with i


I always get a "deadlock waiting for " when I loop the iterator.


A working walkaround is:



q_i = MyModel.query()
instances = q_i.iter()
if instances:
instances = list(instances)


Someone knows why that next() does not work as I expected? Some more elegant and/or efficient solution? Thank you in advance.



asked 1 min ago






Aucun commentaire:

Enregistrer un commentaire