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


Groups > comp.lang.python > #77801

Re: Example of python service running under systemd?

Path csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!goblin1!goblin2!goblin.stu.neva.ru!newsfeed.xs4all.nl!newsfeed1.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail
Return-Path <rosuav@gmail.com>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.001
X-Spam-Evidence '*H*': 1.00; '*S*': 0.00; 'python,': 0.02; 'debug': 0.07; 'important,': 0.07; 'none:': 0.07; 'parser': 0.07; 'args)': 0.09; 'try:': 0.09; 'way:': 0.09; 'cc:addr:python-list': 0.11; 'advantage.': 0.16; 'bugs.': 0.16; 'etc?': 0.16; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'mode,': 0.16; 'reload': 0.16; 'simpler,': 0.16; 'subject:under': 0.16; 'subject:python': 0.16; 'wrote:': 0.18; 'code.': 0.18; 'bit': 0.19; 'code,': 0.22; 'handles': 0.22; 'cc:addr:python.org': 0.22; 'cc:2**0': 0.24; 'sort': 0.25; "i've": 0.25; 'handling': 0.26; 'header:In-Reply-To:1': 0.27; 'generally': 0.29; 'message- id:@mail.gmail.com': 0.30; 'code': 0.31; 'usually': 0.31; '(although': 0.31; 'branches': 0.31; 'sep': 0.31; 'handled': 0.32; 'option': 0.32; 'quite': 0.32; 'fri,': 0.33; 'test': 0.35; 'but': 0.35; 'received:google.com': 0.35; 'there': 0.35; 'false': 0.36; 'reality': 0.36; 'subject:service': 0.36; 'method': 0.36; 'subject:?': 0.36; 'skip:o 20': 0.38; 'pm,': 0.38; '12,': 0.39; 'itself': 0.39; 'skip:p 20': 0.39; 'simple': 0.61; 'kind': 0.63; 'more': 0.64; 'on...': 0.68; 'etc,': 0.84; 'forks': 0.84; 'pike': 0.84; 'shutdown': 0.84; 'to:none': 0.92
DKIM-Signature v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:cc :content-type:content-transfer-encoding; bh=3FBbjpLLxsADZ++Y1L12yFCYQp9Q2Vc/5+Be982SU5w=; b=PTCO21E6ZT0axQGcKgPOA8urkMVrNUulMQfY/N6b+Ff8M6SOJA5kzwKk9CoqbknVT7 sf929AMCmTb6+mgoSVx1pLIseFeKns0sDOyN6C5LNWwwMsLjxE+UcVMuh4iQEKP29/Oc ZmHdA+0q9IS84pCMkFRw292RhLTKAjxo0nOW0CkFCaH6O/yhIoquq3wA6/chQr03jvm6 iZCm1bvsI1ZaVf9b7a3CUDONLEKxeCd42dfxWdsbxcjZzYiwxOggkhiQyQBgN4HWT582 OVIC4B+5E5duLVVTkaTXDcuuOtk26nnkxG8yyzdQVn+yS4exnhPzrv7RyjEn55WKBGdk PXSw==
MIME-Version 1.0
X-Received by 10.50.30.72 with SMTP id q8mr267861igh.14.1410509700147; Fri, 12 Sep 2014 01:15:00 -0700 (PDT)
In-Reply-To <20140912061806.GB3333@arxnet.hu>
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>
Date Fri, 12 Sep 2014 18:15:00 +1000
Subject Re: Example of python service running under systemd?
From Chris Angelico <rosuav@gmail.com>
Cc "python-list@python.org" <python-list@python.org>
Content-Type text/plain; charset=UTF-8
Content-Transfer-Encoding quoted-printable
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.13968.1410509703.18130.python-list@python.org> (permalink)
Lines 44
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1410509703 news.xs4all.nl 2830 [2001:888:2000:d::a6]:34090
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:77801

Show key headers only | View raw


On Fri, Sep 12, 2014 at 4:18 PM, Ervin Hegedüs <airween@gmail.com> wrote:
> is there any other reason outside the debugging?
>
> Of course, I've handled that in a simple way:
>
>     parser = optparse.OptionParser()
>
>     parser.add_option("-d",
>                       "--debug",
>                         action="count",
>                         dest="debug_mode",
>                         help="Start process in debug mode, not forking.")
>
>     (options, args) = parser.parse_args()
>
>     debug_mode = True
>     if options.debug_mode is None:
>
>         debug_mode = False
>         try:
>             pid = os.fork()
>             if pid > 0:
>                ....
>
> And of course, I've handled the signals, logfiles and so on...

1) You don't need all of the above code.
2) You don't need to test all of that code.

And that code is significantly abbreviated. In reality it's quite a bit longer.

Having less code branches is itself an advantage. If I can accomplish
everything with simple top-down code, why go for a -d option and then
an alternative method that forks, forks again, handles signals, etc,
etc, etc? (Although handling signals may still be important, if I want
some kind of more orderly shutdown on SIGTERM, or if I want SIGHUP to
do some sort of reload - not usually in Python, but my Pike code
generally takes SIGHUP to mean "reload your code from the disk".) The
simpler, the better. Less code => less bugs.

ChrisA

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


Thread

Re: Example of python service running under systemd? Chris Angelico <rosuav@gmail.com> - 2014-09-12 18:15 +1000

csiph-web