yielding a value from a coroutine

29 views
Skip to first unread message

Kashif Razzaqui

unread,
May 29, 2015, 2:36:39 AM5/29/15
to python...@googlegroups.com
folks I was trying to yield a value from a coroutine but I find that it is explicitly prevented in tasks.py, I was hoping to understand why this isn't possible and if there is some other way to achieve this.

the following is an example of the kind of code I was trying to write, would appreciate any help/comments.


def page(func):
@wraps(func)
def wrapper(cls, *args, **kwargs):
if 'offset' not in kwargs:
kwargs['offset'] = 0
limit = kwargs.get('limit', 100)

with (yield from cls.get_cursor(_CursorType.NAMEDTUPLE)) as c:
while c.rowcount == -1 or c.rowcount == limit:
query, values = func(cls, *args, **kwargs)
print(query, values)
yield from c.execute(query, values)
yield (yield from c.fetchall())
kwargs['offset'] += limit
return wrapper
Reply all
Reply to author
Forward
0 new messages