Path: csiph.com!fu-berlin.de!uni-berlin.de!not-for-mail From: Oscar Benjamin Newsgroups: comp.lang.python Subject: Re: Cannot step through asynchronous iterator manually Date: Sat, 30 Jan 2016 18:22:21 +0000 Lines: 22 Message-ID: References: Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 X-Trace: news.uni-berlin.de VdZ+m0RhJ9Pj14DXmSAGAQsmB6qPB8/hQ5qrIuarlZfA== Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.007 X-Spam-Evidence: '*H*': 0.99; '*S*': 0.00; 'cc:addr:python-list': 0.09; 'rows': 0.09; 'url:github': 0.09; 'syntax': 0.13; 'appropriate': 0.14; '2))': 0.16; '2016': 0.16; 'async': 0.16; 'cc:name:python': 0.16; 'iterator': 0.16; 'itertools': 0.16; 'received:io': 0.16; 'received:psf.io': 0.16; 'wrote:': 0.16; 'versions': 0.20; 'cc:2**0': 0.20; 'cc:addr:python.org': 0.20; 'are.': 0.22; 'third-party': 0.23; "haven't": 0.24; 'import': 0.24; 'implemented': 0.24; 'header:In-Reply-To:1': 0.24; 'message- id:@mail.gmail.com': 0.27; 'module.': 0.27; 'class': 0.33; 'received:google.com': 0.35; 'done': 0.35; 'but': 0.36; 'there': 0.36; 'received:209.85': 0.36; 'subject:: ': 0.37; 'suggestion': 0.37; 'wanted': 0.37; 'january': 0.38; 'received:209': 0.38; 'anything': 0.38; 'sure': 0.39; 'provide': 0.61; 'further': 0.62; 'await': 0.76; 'oscar': 0.84; 'url:master': 0.84 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc:content-type; bh=zIZyfrEuOSgPFcF7GiHfl43znM4xP4jmm+d0U3jCppM=; b=FVXvuvzp+ZETcnH4Eb0UscfR8kMFvpj+dggqm117G00XEd2kKZJAjVYWWIA2Tr3JfR 5KA5ZC3iFcnI3QbYUOvPKzGV9qcNOE08ZsLeG23x+zM46xfrrf6Ds7zgwY9zOq3XzTy5 NJdA36ur4GcPgxaC3IqYseJcLQdC/BELc/N9qoY3cSsddRWU6FkUpejsjbW7Hgwj4Xs0 fmrXnfElTET4FUT3bwIwf5wtjWjmDWJz0bGpFsBY/8C36tYlMADg6S4ow/V/ixplv5T2 I0w1KL7BzGoAnCkiMVtAAmv4geT3hr6FdbAasbvf1l8GgTl7rFsLVPBkdbFCX+1Ms/AI AVZA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to:cc:content-type; bh=zIZyfrEuOSgPFcF7GiHfl43znM4xP4jmm+d0U3jCppM=; b=e75Odudowee9BAFpP0Jqhzic+KqxegHobXraKY5lIxOXrlJenKWeqhaWNLGyymfgU6 vNtXnsS/bgdLIFRzhJb47w/0RC07dNNEQx9XJJuiE7nOHLGGDlYGjoTrOF8AAYqmvVa0 qDN+XGusLhYhPBbLlLHHITy1Hx+Q4g9upQi/wyWNzj7xfbBB2F2WYkY79Hxi9yBDx06d UWBinp1VDYXmtWQ0zSf2Bcxi92QpgeCUhrg62CdViPQj92i7pgPQPmGHPXNMsrcGXFDO n8rWk71CgaspT73AJcgUJl0AtLiefA5akXiXRGl7Rne9ITYInCPmqAAwmuVF/ZiWahfz gOoQ== X-Gm-Message-State: AG10YOTq8Ohd1xjx7RQq0aE9TpJS9d8jNqb0hvvT4kU11o/jPa1InDJoLsqvfxtEw0U3wjsNCAW/Oe8bOCJF/w== X-Received: by 10.112.135.39 with SMTP id pp7mr4406528lbb.43.1454178160960; Sat, 30 Jan 2016 10:22:40 -0800 (PST) In-Reply-To: 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:102308 On 30 January 2016 at 16:42, Ian Kelly wrote: >> AFAICT there's no generator-function-style syntax for writing an async >> iterator so you'd have to make a class with the appropriate methods if >> you wanted to be able to loop over aslice with async for. > > Before you go any further with this, be sure to check out the aitertools > third-party module. I haven't done anything with it myself, but it already > claims to provide aiter and anext as well as async versions of everything > in the standard itertools module. Right you are. There is aslice and it is implemented as a class with __anext__ etc. methods: https://github.com/asyncdef/aitertools/blob/master/aitertools/__init__.py#L747 My original suggestion just becomes: from aitertools import alist, islice rows = await alist(islice(cur, 2)) # pull at most 2 rows -- Oscar