Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #77822

Re: Python stdout goes where under systemd? (Was: Example of python service running under systemd?)

Subject Re: Python stdout goes where under systemd? (Was: Example of python service running under systemd?)
From Travis Griggs <travisgriggs@gmail.com>
Date 2014-09-12 14:45 -0700
References (4 earlier) <5412548A.1090507@gmail.com> <CAPTjJmq4fYOs-qvko9q9S=M7PNGOLPBTDiPZ6R0PvMrAULC=3g@mail.gmail.com> <20140912061806.GB3333@arxnet.hu> <CAPTjJmqTYmGy8WHm5a3Vo-A+vXjoXJWf4C0Nr7qXeBuHSEC_AQ@mail.gmail.com> <997C8621-DD83-461C-9F2E-45BB360DAC18@gmail.com>
Newsgroups comp.lang.python
Message-ID <mailman.13983.1410558347.18130.python-list@python.org> (permalink)

Show all headers | View raw


On Sep 12, 2014, at 12:05 PM, Travis Griggs <travisgriggs@gmail.com> wrote:

> Thanks all for the help/advice. I’m getting there.
> 
> To experiment/learn, I made a simple python program (/Foo/cyclic.py):
> 
>    #!/usr/bin/env python3
> 
>    import time
> 
>    while True:
>        time.sleep(5)	
>        with open('sound', 'r') as file:
>            currentValue = file.read()
>        otherValue = 'tick' if currentValue == 'tock' else 'tock'
>        with open('sound', 'w') as file:
>            file.write(otherValue)
>        print(currentValue, '->', otherValue)
> 
> Run from the command line, this tick-tocks nicely, both outputting, as well as updating the ‘/Foo/sound’ file on a 5 second period.
> 
> I then created a simple .service file:
> 
>    [Unit]
>    Description=Foo for learning service
>    After=network-online.target
> 
>    [Service]
>    Type=simple
>    ExecStart=/Foo/cyclic.py
>    WorkingDirectory=/Foo
>    StandardOutput=journal
> 
>    [Install]
>    WantedBy=multi-user.target
> 
> I chose to be “explicit” with some of the default options (Type and StandardOutput).
> I finally executed:
> 
>    systemctl --system daemon-reload
>    systemctl enable foo
>    systemctl start foo
> 
> It seems to work. Almost. The file is being updated regularly (watch cat /Foo/sound shows the change happening). But I can’t seem to find the output from my print() statement. journalctl -f doesn’t show anything. Nor does tail -f /var/log/syslog or any of the others. It just seems to be going nowhere? Is there something I need to do special to get the print() output going somewhere logable?
> 

Arghhh… I’ll answer my own question here. I wasn’t patient enough, when I checked after lunch, I found I had a mountain of tick/tock entries in journalctl -f. Python print() is buffered, so it wasn’t showing up except in huge blocks. Changed the .service file to start with -u and everything works as expected now.

Back to comp.lang.python | Previous | Next | Find similar | Unroll thread


Thread

Re: Python stdout goes where under systemd? (Was: Example of python service running under systemd?) Travis Griggs <travisgriggs@gmail.com> - 2014-09-12 14:45 -0700

csiph-web