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?)

Path csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!news.mixmin.net!proxad.net!feeder1-2.proxad.net!news.tele.dk!news.tele.dk!small.news.tele.dk!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail
Return-Path <travisgriggs@gmail.com>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.026
X-Spam-Evidence '*H*': 0.95; '*S*': 0.00; 'output': 0.05; 'subject:Python': 0.06; 'python3': 0.07; 'skip:/ 10': 0.09; 'python': 0.11; "'w')": 0.16; 'file.read()': 0.16; 'statement.': 0.16; 'subject:?)': 0.16; 'subject:Was': 0.16; 'subject:under': 0.16; 'subject:where': 0.16; 'travis': 0.16; 'true:': 0.16; 'subject:python': 0.16; 'wrote:': 0.18; 'seems': 0.21; 'command': 0.22; 'import': 0.22; 'to:name:python-list@python.org': 0.22; 'entries': 0.24; 'question': 0.24; 'options': 0.25; 'updating': 0.26; 'second': 0.26; 'somewhere': 0.26; 'header:In-Reply-To:1': 0.27; 'work.': 0.31; 'getting': 0.31; 'file:': 0.31; 'sep': 0.31; 'file': 0.32; 'there.': 0.32; 'checked': 0.32; 'run': 0.32; 'skip:# 10': 0.33; 'updated': 0.34; 'created': 0.35; 'except': 0.35; 'something': 0.35; 'but': 0.35; 'received:google.com': 0.35; 'there': 0.35; 'patient': 0.36; 'subject:service': 0.36; 'shows': 0.36; 'thanks': 0.36; 'being': 0.38; 'expected': 0.38; 'message- id:@gmail.com': 0.38; 'others.': 0.38; 'to:addr:python-list': 0.38; 'pm,': 0.38; 'does': 0.39; '12,': 0.39; 'to:addr:python.org': 0.39; 'changed': 0.39; 'simple': 0.61; 'header:Message-Id:1': 0.63; 'show': 0.63; 'finally': 0.65; 'mountain': 0.65; 'charset:windows-1252': 0.65; 'anything.': 0.68; 'line,': 0.68; 'default': 0.69; 'special': 0.74; '2014,': 0.84; 'doesn\x92t': 0.84; 'can\x92t': 0.91; 'period.': 0.95
DKIM-Signature v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=content-type:mime-version:subject:from:in-reply-to:date :content-transfer-encoding:message-id:references:to; bh=So7hnvw8VWu7Qnj+OrRUvijh1/mt2KGpG7xu9g6Aohk=; b=hmF9yl4k1UatNdYh9SzSYd+QOLmZLE/6SRfkmWuIdvivtpJ5p/UEWy6c39Bel9KxDp lY4t3soyo+l5OfV3sR209/U86go2FQd/QFMtI+38gHxFSesNW7/wvbpvQQJkoQzQUiSS V/fEENqkY0yxLa6soZJ8aIr0odcn8PdgkN3iQW8GNJMdkc38K5kVDe+5HXh/35Z0wE7c nHDaub/iRGHC75FdbbepIYQ0I1TiW4NehA3IcZc3pqv1PurHVFilyjZJ3taTEHe3Fhe4 cy7KMkznWnxH4vbXihDHIfAfjajQu2JpmyLS+uoi9EmQhKy6vNhq0/qjieWUSXlulPgA xDAw==
X-Received by 10.68.175.99 with SMTP id bz3mr16410687pbc.112.1410558344634; Fri, 12 Sep 2014 14:45:44 -0700 (PDT)
Content-Type text/plain; charset=windows-1252
Mime-Version 1.0 (Mac OS X Mail 7.3 \(1878.6\))
Subject Re: Python stdout goes where under systemd? (Was: Example of python service running under systemd?)
From Travis Griggs <travisgriggs@gmail.com>
In-Reply-To <997C8621-DD83-461C-9F2E-45BB360DAC18@gmail.com>
Date Fri, 12 Sep 2014 14:45:42 -0700
Content-Transfer-Encoding quoted-printable
References <FE4C3550-8958-4F72-8AFE-62AA7248D6AF@gmail.com> <CAMw+j7+LQL_+77ejCFVSqWap7Rk9gS_Wu5d3y0gT1UpB8hiZAA@mail.gmail.com> <6B97B7A5-0816-401E-9BDD-A23FFC646985@gmail.com> <20140911212921.GB26465@arxnet.hu> <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>
To "python-list@python.org" <python-list@python.org>
X-Mailer Apple Mail (2.1878.6)
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.15
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <https://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list/>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.13983.1410558347.18130.python-list@python.org> (permalink)
Lines 60
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1410558347 news.xs4all.nl 2925 [2001:888:2000:d::a6]:57362
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:77822

Show key headers only | 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