-
Notifications
You must be signed in to change notification settings - Fork 720
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Improve documentation for external event loop #147
Comments
There's more than one non-public member in the second example. _state was being used too. I was thinking that using asyncio to manage this and other sockets would be piece of cake as well. Now I'm second guessing myself. |
In my opinion, the existing documentation on external event loops is sufficient. That is, if you know in general how the select system call work. In a nutshell: You can ask the operating system if there is anything to read from a file descriptor or if there's enough buffer space for writing something to a file descriptor. And select will block until the answer is "yes" to at least one of the questions (or a timeout is hit).
Yes, there is. There are 4 possible situations here: You want to write something, or you don't. There's space for writing or there isn't.
The correct approach is to first determine if you want to write. If so, ask select if you can write. If so, do write.
Both examples are bad, see https://dev.eclipse.org/mhonarc/lists/paho-dev/msg03998.html
I believe it's not possible to use asyncio here, without changing paho.mqtt first. See https://dev.eclipse.org/mhonarc/lists/paho-dev/msg03999.html for an idea to fix this. See also https://github.com/mossblaser/aiomqtt "Unfortunately the author was unable to work out how to integrate paho-mqtt's event loop into asyncio". The author is not to blame :-) I'll try to write a correct example using https://docs.python.org/3/library/select.html#select.select for #72. This should suffice as documentation. And I'll try to implement changes so asyncio and other event loops can actually be used, and provide an example for this too. |
Add four more callbacks and documentation to make it possible to use external event loops other than select(). This could e.g. be asyncio, twisted or gevent. * on_socket_open - called when a new socket was opened. --> watch read * on_socket_close - called when the socket is about to be closed. --> unwatch read * on_socket_register_write - called when mqtt wants to write. --> watch write * on_socket_unregister_write - called when mqtt is finished writing. --> unwatch write Add examples how to write external event loops: * loop_select.py - select() based event loop, works without the other changes. * loop_asyncio.py - asyncio based event loop, utilizes the new callbacks. This should also fix the issues eclipse#72 and eclipse#147. Signed-off-by: Jörn Heissler <eclipse.org@wulf.eu.org>
Add four more callbacks and documentation to make it possible to use external event loops other than select(). This could e.g. be asyncio, twisted or gevent. * on_socket_open - called when a new socket was opened. --> watch read * on_socket_close - called when the socket is about to be closed. --> unwatch read * on_socket_register_write - called when mqtt wants to write. --> watch write * on_socket_unregister_write - called when mqtt is finished writing. --> unwatch write Add examples how to write external event loops: * loop_select.py - select() based event loop, works without the other changes. * loop_asyncio.py - asyncio based event loop, utilizes the new callbacks. This should also fix the issues eclipse#72 and eclipse#147. Signed-off-by: Jörn Heissler <eclipse.org@wulf.eu.org>
Add four more callbacks and documentation to make it possible to use external event loops other than select(). This could e.g. be asyncio, twisted or gevent. * on_socket_open - called when a new socket was opened. --> watch read * on_socket_close - called when the socket is about to be closed. --> unwatch read * on_socket_register_write - called when mqtt wants to write. --> watch write * on_socket_unregister_write - called when mqtt is finished writing. --> unwatch write Add examples how to write external event loops: * loop_select.py - select() based event loop, works without the other changes. * loop_asyncio.py - asyncio based event loop, utilizes the new callbacks. This should also fix the issues eclipse#72 and eclipse#147. Signed-off-by: Jörn Heissler <eclipse.org@wulf.eu.org>
Closing this because #235 improved the situation (and this issue is now pretty stale!). If you believe this is still a problem please feel free to open a new issue with updated examples etc. |
Related: #72
I think the documentation could do with some clarification/small additions for external event loop usage.
Whilst incoming MQTT data is quite self-explanatory (set the event loop to watch for read availability on the socket(), and then run loop_read()), the writing of data is less clear:
I would be willing to draft some documentation, with an example using asyncio, if these points could be clarified.
*On a side note, if this is the preferred option for waiting for new outgoing packets, should there be a public interface for this?
The text was updated successfully, but these errors were encountered: