Tinche / aiofiles

File support for asyncio
Apache License 2.0
2.67k stars 149 forks source link

Deprecation warning on __aiter__ #14

Open DavidMertz opened 7 years ago

DavidMertz commented 7 years ago

In a small bit of test code I trigger (I think) the changed behavior of aiter between Python 3.5 and 3.6. The code is this below, with the error. This is my very first use of aiofiles (and almost my first use of asyncio) so I'm happy to accept that I could be doing something wrong. :wink:

async def query_feed(src, queue):
    print('Starting read from {}'.format(src))
    # The file-handle itself can be non-blocking and asynchronous
    async with aiofiles.open(src) as fh:
        async for line in fh:
            await asyncio.sleep(2)
            await queue.put(line.strip())
            # print() is synchronous and completes atomically w/o control switch
            print("From feed:\t", line.strip())
DeprecationWarning: 'AsyncTextIOWrapper' implements legacy __aiter__ protocol; __aiter__ should return an asynchronous iterator, not awaitable
Tinche commented 7 years ago

Hm. I'll take a look.

Here's the relevant documentation: https://docs.python.org/3/reference/datamodel.html#asynchronous-iterators.

asvetlov commented 7 years ago

aiohttp uses workaround to solve the issue depending on python version.