<div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">2015-05-02 17:22 GMT+02:00 Jörg Thalheim <span dir="ltr"><<a href="mailto:joerg.systemd@higgsboson.tk" target="_blank">joerg.systemd@higgsboson.tk</a>></span>:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><div class=""><div class="h5">On Sat, 2 May 2015 16:31:44 +0200<br>
Ludovic Gasc <<a href="mailto:gmludo@gmail.com">gmludo@gmail.com</a>> wrote:<br>
<br>
> 2015-05-02 16:18 GMT+02:00 Zbigniew Jędrzejewski-Szmek<br>
> <<a href="mailto:zbyszek@in.waw.pl">zbyszek@in.waw.pl</a>>:<br>
><br>
> > On Sat, May 02, 2015 at 03:34:52PM +0200, Ludovic Gasc wrote:<br>
> > > Ok, my bad, I didn't see JournalHandler class to use with Python<br>
> > > logging:<br>
> > ><br>
> > <a href="http://www.freedesktop.org/software/systemd/python-systemd/journal.html#journalhandler-class" target="_blank">http://www.freedesktop.org/software/systemd/python-systemd/journal.html#journalhandler-class</a><br>
> > ><br>
> > > Nevertheless, my question about communication between Python and<br>
> > > journald remains.<br>
> > Can you rephrase the question? I don't quite understand what<br>
> > functionality you're missing from<br>
> ><br>
> > <a href="http://www.freedesktop.org/software/systemd/python-systemd/journal.html#systemd.journal.send" target="_blank">http://www.freedesktop.org/software/systemd/python-systemd/journal.html#systemd.journal.send</a><br>
> > .<br>
> ><br>
> ><br>
> In AsyncIO, when you interact with the outside world, you need to use<br>
> "yield from", for example:<br>
> <a href="https://docs.python.org/3/library/asyncio-stream.html#tcp-echo-client-using-streams" target="_blank">https://docs.python.org/3/library/asyncio-stream.html#tcp-echo-client-using-streams</a><br>
><br>
> "yield from" means to the Python interpreter to "pause" the coroutine<br>
> to work on another coroutine until data arrive.<br>
> To be efficient, I/O should handled by AsyncIO, even if some<br>
> workarounds are possible if the raw socket isn't accessible.<br>
><br>
> If this pattern is useful for HTTP requests, for logging where you<br>
> shouldn't wait a return, it isn't very critical, especially if you use<br>
> syslog protocol with UNIX socket.<br>
><br>
> Nevertheless, to be sure, I wish to understand how the communication<br>
> works between my process and journald daemon.<br>
<br>
</div></div>AsyncIO was not their, when these bindings were written. Inventing a<br>
asynchron API on top of a synchron API (as provided by sd_journal_sendv) might be hard.<br>
So I have two ideas here:<br>
<br>
1. use a background thread, which writes messages to journald from a ring buffer and fill this ringbuffer from your application.<br></blockquote><div><br></div><div>As mentioned by Zbigniew, it should be slower that send directly, especially because with Python we have GIL for threads.</div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">
2. write to the unix socket /run/systemd/journal/socket directly with python and asyncIO,<br>
   this is not as hard as it sounds because it is still some kind of text protocol. The coreos guys did this in go here:<br>
   <a href="https://github.com/coreos/go-systemd/blob/master/journal/send.go#L68" target="_blank">https://github.com/coreos/go-systemd/blob/master/journal/send.go#L68</a></blockquote><div><br></div><div>It's often the way followed by the AsyncIO community, rewrite or cherry pick a protocol business logic and handle sockets with AsyncIO directly.</div><div>Nevertheless, in the case of UNIX socket, especially with a datagram packet where you don't wait to send something, you have almost no benefit to adapt that for AsyncIO.</div><div><br></div><div>Thank you guys for theses answers, I'm continuing to play with that, I think you did everything I need to work.</div><div>If I have an issue, I'll open a pull request and post the patch on this mailing-list.</div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><br>
<br>_______________________________________________<br>
systemd-devel mailing list<br>
<a href="mailto:systemd-devel@lists.freedesktop.org">systemd-devel@lists.freedesktop.org</a><br>
<a href="http://lists.freedesktop.org/mailman/listinfo/systemd-devel" target="_blank">http://lists.freedesktop.org/mailman/listinfo/systemd-devel</a><br>
<br></blockquote></div><br></div></div>