Understanding blocking and non-blocking code

So far, we have been working with blocking calls that processed MQTT-related network traffic and dispatched callbacks. Whenever we called the client.loop method in the previous examples, the method used the default values for the two optional arguments: 1 for timeout and 1 for max_packets. The method blocks for up to one second, that is, the value of the timeout argument, to handle incoming or outgoing data. The method runs with a synchronous execution, and therefore, the next line of code won't be executed until this method returns. We called the client.loop method in the main thread, and therefore, no other code can be executed in this thread while the client.loop method is blocking.

In our first ...

Get Hands-On MQTT Programming with Python now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.