This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author greckov
Recipients asvetlov, greckov, yselivanov
Date 2020-12-02.12:17:27
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1606911447.68.0.828780901691.issue42538@roundup.psfhosted.org>
In-reply-to
Content
Hi! I've met strange behaviour related to the coroutine execution. Probably it's somehow related to the asyncio.Queue get() method. I have the following lines of code:
class WeightSource:
    def __init__(self):
        self._queue = asyncio.Queue(maxsize=1)
    def __aiter__(self):
        return self
    async def __anext__(self):
        return await self._queue.get()

async def _preconfigure(app: web.Application) -> None:
    setup_db()
    # asyncio.create_task(WeightSource.listen_scales('/dev/ttyACM0', 9600)
    asyncio.create_task(handle_weight_event_creation()) # coroutine prints WEIGHT <int>
    await create_track_tasks()

async def create_track_tasks():
    asyncio.create_task(track_scales_availability())
    asyncio.create_task(track_crm_availability())

async def track_scales_availability():
    async for weight in WeightSource():
        print(weight)

When I'm trying to run _preconfigure coroutine (automatically started by aiohttp), i see the message: ERROR:asyncio:Task was destroyed but it is pending. The strange things two:
The process and loop remains alive (so by the logic error should be not shown) and the second thing is when I export PYTHONASYNCIODEBUG=1 everything works well without any error. 
On unset this variable the error returns. When I don't use asyncio.Queue and just place asyncio.sleep(), coroutine doesn't fall. Error happens inside the `async for weight in WeightSource()` statement. Why PYTHONASYNCIODEBUG changes behaviour?
History
Date User Action Args
2020-12-02 12:17:27greckovsetrecipients: + greckov, asvetlov, yselivanov
2020-12-02 12:17:27greckovsetmessageid: <1606911447.68.0.828780901691.issue42538@roundup.psfhosted.org>
2020-12-02 12:17:27greckovlinkissue42538 messages
2020-12-02 12:17:27greckovcreate