Path: csiph.com!feeder.erje.net!2.eu.feeder.erje.net!newsfeed.kamp.net!newsfeed.kamp.net!fu-berlin.de!uni-berlin.de!not-for-mail From: "Frank Millman" Newsgroups: comp.lang.python Subject: Re: Cannot step through asynchronous iterator manually Date: Sat, 30 Jan 2016 15:45:51 +0200 Lines: 30 Message-ID: References: Mime-Version: 1.0 Content-Type: text/plain; format=flowed; charset="iso-8859-1"; reply-type=original Content-Transfer-Encoding: 7bit X-Trace: news.uni-berlin.de 7a5IX/ksjVi3YGrtWe3ewwynH4giwp63Em1TjPgDuGkw== Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.003 X-Spam-Evidence: '*H*': 0.99; '*S*': 0.00; 'elif': 0.04; 'base.': 0.05; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'rows': 0.09; 'thread': 0.10; '2))': 0.16; 'consume': 0.16; 'itertools': 0.16; 'readable': 0.16; 'received:80.91.229.3': 0.16; 'received:io': 0.16; 'received:plane.gmane.org': 0.16; 'received:psf.io': 0.16; 'row': 0.16; 'skip:n 70': 0.16; 'variations': 0.16; 'wrote': 0.23; 'header:In-Reply-To:1': 0.24; 'example': 0.26; 'header:X -Complaints-To:1': 0.26; 'equivalent,': 0.29; 'idea,': 0.29; 'similar': 0.33; 'except': 0.34; 'but': 0.36; 'too': 0.36; 'should': 0.36; 'there': 0.36; 'to:addr:python-list': 0.36; 'subject:: ': 0.37; 'thanks': 0.37; 'received:org': 0.37; 'to:addr:python.org': 0.40; 'your': 0.60; 'back': 0.62; 'more': 0.63; 'realise': 0.66; 'frank': 0.72; 'square': 0.76; 'leisure': 0.84; 'choose.': 0.91 X-Injected-Via-Gmane: http://gmane.org/ X-Gmane-NNTP-Posting-Host: 197.86.205.12 In-Reply-To: X-MSMail-Priority: Normal Importance: Normal X-Newsreader: Microsoft Windows Live Mail 15.4.3502.922 X-MimeOLE: Produced By Microsoft MimeOLE V15.4.3502.922 X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.20+ Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Xref: csiph.com comp.lang.python:102304 "Oscar Benjamin" wrote in message news:CAHVvXxSA0Yq4VOYy6qycgXxVpL5zZGM8muUi+1VmeZD8CRgtvg@mail.gmail.com... > > The simplest thing would just be to call list(cur) but I realise that you don't want to consume more than 2 rows from the database so just use islice: > > rows = list(islice(cur, 2)) # pull at most 2 rows > if not rows: > # no rows > elif len(rows) > 1: > # too many rows > row = rows[0] > I like the idea, but I don't think it would work with an asychronous iterable. OTOH it should not be difficult to roll your own using the example in the itertools docs as a base. Except that the example uses next(it) internally, and this thread started with the fact that there is no asychronous equivalent, so I might be back to square one. But these are all variations on a similar theme, so I don't think it matters which one I choose. I will go through them at my leisure and pick the most readable one. Thanks Frank