Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [paho-dev] Python Paho with Asyncio


On Thu, Nov 23, 2017 at 04:24:37PM +0000, Ioannis Latousakis wrote:

> I am building a project that uses asyncio  + web sockets (autobahn),
> and I also need to push the communications to AWS IoT. Their python SDK
> is using Paho. I am trying to figure out if this library will create
> any issue when run in asyncio coroutines. As I am new to asyncio, I am
> not sure what to look out for. I timed calls to publish, and calls on
> my callback function, and the numbers are not worrying, also setting
> asyncio loop to debug did not raise any warnings. Are there any issues
> I should be aware of?

You have to think of asyncio loops vs. MQTT client loops, you can't
have them both ;-).

For asyncio this normally means you can not use MQTT's "forever" loop,
but you have to call loop_read(), loop_write(), and loop_misc() at
the right spots.

I used the asyncio event loop add_reader and add_writer functions to
watch the MQTT file descriptor, which is client.socket().fileno(), just
as you would do when using ordinary select() system calls i.s.o. the
MQTT loop:

Hope this helps a bit,

--    Jos Vos <jos@xxxxxx>
--    X/OS Experts in Open Systems BV   |   Office: +31 20 6938364
--    Amsterdam, The Netherlands        |   Mobile: +31 6 26216181

Back to the top