OK, that looks like a real use case and proof that UNIX sockets used as datagrams are actually used. If you submit a PR (to CPython -- the separate asyncio repo is dead) it should be possible to get this into Python 3.7.
On Tue, Aug 15, 2017 at 3:52 PM, Ludovic Gasc <gml...@gmail.com> wrote: > On Wednesday, February 19, 2014 at 4:55:03 PM UTC+1, Guido van Rossum > wrote: >> >> Because that would require duplicating the logic in >> create_datagram_endpoint(), which is totally separate (all the way down to >> the I/O callbacks). >> >> Feel free to add a feature request to the tracker for this though. Be >> sure to indicate an actual use case (rather than just abstract interest). >> E.g. do you expect to need this in OpenStack? How? >> > > Hi everybody, > > I would wake-up this thread because I have a concrete use case to have > that in AsyncIO, even if it would the only one concrete use case from a > production environment: > systemd has a watchdog mechanism and a way to communicate between a daemon > and systemd. > It uses a UNIX socket with DGRAM, the mechanism is named sd_notify. > > For example, a Python that implements sd_notify: https://github.com/ > bb4242/sdnotify/blob/master/sdnotify/__init__.py#L35 > Another example in Python: https://gist.github.com/Spindel/ > 1d07533ef94a4589d348#file-watchdogged-py-L78 > > More technical documentation about sd_notify protocol: https://www. > freedesktop.org/software/systemd/man/sd_notify.html > > In fact, if somebody has a workaround or a way to implement that gently > with AsyncIO, it would be awesome, because I need to ping-pong with systemd > to say that my daemon is still alive. > Thanks for your help. > > I have tried to find a way with loop.create_datagram_endpoint() that > would be the most closer what I want and a custom socket, I have this error: > > File > "/usr/local/pythonz/pythons/CPython-3.6.2/lib/python3.6/asyncio/base_events.py", > line 951, in create_datagram_endpoint > yield from waiter > AssertionError: yield from wasn't used with future > > My piece of code: > > sock = socket.socket(socket.AF_UNIX, socket.SOCK_DGRAM) > sock.setblocking(False) > > sock.connect(os.environ["NOTIFY_SOCKET"]) > > transport, protocol = loop.create_datagram_endpoint( > lambda: WatchDogClientProtocol(loop), > sock=sock) > > -- --Guido van Rossum (python.org/~guido)