Because of the iterator construction in __init__, any attempt to iterate over client.messages after the initial iteration will yield no data.
Here's an MVP of the actual defect:
import sys
import os
# Change to the "Selector" event loop if platform is Windows
if sys.platform.lower() == "win32" or os.name.lower() == "nt":
from asyncio import set_event_loop_policy, WindowsSelectorEventLoopPolicy
set_event_loop_policy(WindowsSelectorEventLoopPolicy())
import asyncio
import aiomqtt
async def main():
async with aiomqtt.Client("test.mosquitto.org") as client:
async def listen():
async for message in client.messages:
print(message.payload)
listen_task = asyncio.create_task(listen())
await client.subscribe("temperature/#")
try:
await asyncio.wait_for(listen_task, timeout=0.5)
except asyncio.TimeoutError:
listen_task.cancel()
# Should continue forever
await listen()
raise Exception("Listen returned too early!")
asyncio.run(main())
Running the MVP fails with current main, but works properly after this PR.
Because of the iterator construction in
__init__
, any attempt to iterate overclient.messages
after the initial iteration will yield no data.Here's an MVP of the actual defect:
Running the MVP fails with current
main
, but works properly after this PR.