On Sat, May 02, 2015 at 05:22:49PM +0200, Jörg Thalheim wrote: > On Sat, 2 May 2015 16:31:44 +0200 > Ludovic Gasc <[email protected]> wrote: > > > 2015-05-02 16:18 GMT+02:00 Zbigniew Jędrzejewski-Szmek > > <[email protected]>: > > > > > On Sat, May 02, 2015 at 03:34:52PM +0200, Ludovic Gasc wrote: > > > > Ok, my bad, I didn't see JournalHandler class to use with Python > > > > logging: > > > > > > > http://www.freedesktop.org/software/systemd/python-systemd/journal.html#journalhandler-class > > > > > > > > Nevertheless, my question about communication between Python and > > > > journald remains. > > > Can you rephrase the question? I don't quite understand what > > > functionality you're missing from > > > > > > http://www.freedesktop.org/software/systemd/python-systemd/journal.html#systemd.journal.send > > > . > > > > > > > > In AsyncIO, when you interact with the outside world, you need to use > > "yield from", for example: > > https://docs.python.org/3/library/asyncio-stream.html#tcp-echo-client-using-streams > > > > "yield from" means to the Python interpreter to "pause" the coroutine > > to work on another coroutine until data arrive. > > To be efficient, I/O should handled by AsyncIO, even if some > > workarounds are possible if the raw socket isn't accessible. > > > > If this pattern is useful for HTTP requests, for logging where you > > shouldn't wait a return, it isn't very critical, especially if you use > > syslog protocol with UNIX socket. > > > > Nevertheless, to be sure, I wish to understand how the communication > > works between my process and journald daemon. > > AsyncIO was not their, when these bindings were written. Inventing a > asynchron API on top of a synchron API (as provided by sd_journal_sendv) > might be hard. > So I have two ideas here: I'm not sure if it is worth the trouble. Sending to the journal should be very fast, and the overhead of dispatching to a separate thread is likely to only slow things down.
Zbyszek > 1. use a background thread, which writes messages to journald from a ring > buffer and fill this ringbuffer from your application. > 2. write to the unix socket /run/systemd/journal/socket directly with python > and asyncIO, > 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: > https://github.com/coreos/go-systemd/blob/master/journal/send.go#L68 > _______________________________________________ > systemd-devel mailing list > [email protected] > http://lists.freedesktop.org/mailman/listinfo/systemd-devel _______________________________________________ systemd-devel mailing list [email protected] http://lists.freedesktop.org/mailman/listinfo/systemd-devel
