Hello, MicroPython implementation of (a subset of) asyncio speaking again. And again to report potentially confusing wording in the documentation (which is per previous discussions, also pretty much means "specification").
https://docs.python.org/3/library/asyncio-sync.html#asyncio.Queue.get says: " get() Remove and return an item from the queue. If you yield from get(), wait until a item is available. This method is a coroutine. " So, my reading of the above would be: "Remove and return an item from the queue. If you yield from get(), wait until a item is available. If you don't yield from get() (which apparently means calling it directly), it won't wait until item is available (but do something else, which is underspecified)". But that contradicts statement "This method is a coroutine." Because if it's a coroutine, then the only valid action is to yield from it (well, or for over it, or next() over it). So maybe statement "This method is a coroutine." is not correct and it should be "This method is a coroutine or normal function, depending on how you call it." But very much likely, "If" is the culprit and the source of confusion. Looking at the source confirms that this method is a 100% coroutine, so there can't be any if's - you always yield from it, and it always waits for item to be available if queue is empty. Or maybe meaning of "If you yield from get(), wait until a item is available." is yet something else, like "If you implement this method in your subcalls, and use 'yield' in your implementation, it will cause caller to be suspended until an item is actually available.", but that's even less useful to serve as description of the specific method. The same issue applies to https://docs.python.org/3/library/asyncio-sync.html#asyncio.Queue.put So, please let me know if I'm missing something, or if otherwise this needs a ticket in bugtracker. Thanks! P.S. It actually may be good Python quiz on how to achieve that semantics - to call "function" either directly or as a coroutine. -- Best regards, Paul mailto:[email protected]
