[issue42538] AsyncIO strange behaviour

2020-12-02 Thread Alexander Greckov


New submission from Alexander Greckov :

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 
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?

--
components: asyncio
files: output.txt
messages: 382307
nosy: Alexander-Greckov, asvetlov, yselivanov
priority: normal
severity: normal
status: open
title: AsyncIO strange behaviour
type: behavior
versions: Python 3.7
Added file: https://bugs.python.org/file49644/output.txt

___
Python tracker 
<https://bugs.python.org/issue42538>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue42538] AsyncIO strange behaviour

2020-12-02 Thread Alexander Greckov


Alexander Greckov  added the comment:

Thanks! That's resolved my problem, but this thing wasn't really obvious as for 
me. Probably it would be better to write about this explicitly in docs for the 
create_task. All in all this issue can be closed.

--

___
Python tracker 
<https://bugs.python.org/issue42538>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com