Page 2 of 2

Re: Resilient aysnchronous MQTT optimim use

Posted: Tue Jul 30, 2019 5:00 pm
by kevinkk525
Sorry but with this code I'm starting to doubt your experience (at least in regards of python). You should be able to find the mistakes yourself but I'll give you a hint anyways as you might have misunderstood some underlying concepts (which are the same as in python..):

The queue will always be empty because you don't add anything to it.
Uasyncio and mqtt_as don't access your queue in any way.

If you just want to print the length of the Uasyncio queue use this:

loop=asyncio.get_event_loop()
print(len(loop.waitq))


Re: Resilient aysnchronous MQTT optimim use

Posted: Wed Jul 31, 2019 5:36 am
by pythoncoder
Quite.

Re: Resilient aysnchronous MQTT optimim use

Posted: Wed Jul 31, 2019 11:51 am
by RobinMosedale
Quite right. Asyncio is new to me. Not at all familiar with it and learning

Thanks

Re: Resilient aysnchronous MQTT optimim use

Posted: Wed Jul 31, 2019 5:11 pm
by pythoncoder
kevinkk525 wrote:
Tue Jul 30, 2019 5:00 pm
If you just want to print the length of the Uasyncio queue use this:

loop=asyncio.get_event_loop()
print(len(loop.waitq))
In the general case it's not as simple as that because there are two queues: there is also .runq.

.waitq holds tasks which are suspended pending a time delay whereas .runq holds tasks which are ready to run. If a task yields with

Code: Select all

await asyncio.sleep(0)
it goes straight onto .runq where it may compete for round-robin execution with other similar tasks. Likewise a task on .waitq moves to .runq when its execution time arrives.

Re: Resilient aysnchronous MQTT optimim use

Posted: Wed Jul 31, 2019 6:17 pm
by RobinMosedale
Thank you Peter, that's kind.

I really don't wish to use this thread as a vehicle for me to learn (u)asyncio and bother you two kind and generous people. Just point me to a module/object/function spec.

This really is a diverting branch to facilitating a comms method for what I'm doing elsewhere, and grateful that I can use and monitor this resilient function with some degree of competence. It's an enabler. Once I'm confident that I'm employing the features with reasonable competence, then I'll be off to the main task.

Robin