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


Groups > comp.lang.python > #76822

Re: Halfway point between interactive and daemon?

Path csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!newsfeed.xs4all.nl!newsfeed3.news.xs4all.nl!xs4all!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.008
X-Spam-Evidence '*H*': 0.98; '*S*': 0.00; '(so': 0.07; 'init': 0.07; 'restart': 0.09; 'cc:addr:python-list': 0.11; "(i'm": 0.16; '23,': 0.16; 'fork': 0.16; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'happily': 0.16; 'i\xe2\x80\x99d': 0.16; 'i\xe2\x80\x99m': 0.16; 'latter,': 0.16; 'line),': 0.16; 'optional.': 0.16; 'subject:between': 0.16; 'travis': 0.16; 'sat,': 0.16; 'wrote:': 0.18; 'module': 0.19; 'file,': 0.19; 'command': 0.22; 'aug': 0.22; 'separate': 0.22; 'cc:addr:python.org': 0.22; 'fine': 0.24; 'cc:2**0': 0.24; 'right.': 0.26; 'this:': 0.26; 'header:In-Reply-To:1': 0.27; 'am,': 0.29; "doesn't": 0.30; 'strongly': 0.30; 'message- id:@mail.gmail.com': 0.30; 'away.': 0.31; 'file': 0.32; 'there.': 0.32; 'quite': 0.32; 'running': 0.33; 'minimal': 0.33; 'skip:d 20': 0.34; 'could': 0.34; 'skip:u 20': 0.35; 'something': 0.35; 'case,': 0.35; 'received:google.com': 0.35; 'there': 0.35; 'curious': 0.36; 'picking': 0.36; 'subject:?': 0.36; 'should': 0.36; 'half': 0.37; 'unit': 0.37; 'two': 0.37; 'project': 0.37; 'starting': 0.37; 'server': 0.38; 'little': 0.38; 'expect': 0.39; 'itself': 0.39; 'sure': 0.39; 'system.': 0.39; 'either': 0.39; 'how': 0.40; 'skip:u 10': 0.60; 'is.': 0.60; 'free': 0.61; 'here:': 0.62; 'details': 0.65; 'gotten': 0.74; 'processes,': 0.91; 'to:none': 0.92; 'technique': 0.93
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=nApflq0vRPihH1p9v89m0EJrJ0eggo1ye63KvdvRHnk=; b=SW8KYUJ/ZyHKLtWj5lBt0doeRrhYlPQVo7X1rJdVcjqZtzfdXztMvXXxNssysRxzcz 0zSVDVltWPtTExRgZ3GkYEXhXaMxYtuQlMrvmK/JAAQVDbY8Gragojj1W+ghTFd5Pdq2 qibVNjhdLRQwZmB0732uVCk+wmN4X19DugsQgeGCJWiZ59Wy6dmGpt6qU6llQrYtMiW3 GNGCg8t6WvHMe7Ec3VINAyQAWtQGjC75bvPFx71uv4tN3Pu7afdFty7tgBIsRRs2Ip/B AWnMBo14Po3U3r1PVaap4wa67I/YEDPiUVkToTHZ73U4b2rRuYvMPg+eHE2gMvxN9S/R 3xgA==
MIME-Version 1.0
X-Received by 10.42.4.136 with SMTP id 8mr11184173ics.57.1408739561899; Fri, 22 Aug 2014 13:32:41 -0700 (PDT)
In-Reply-To <3DBE5DB0-3FA8-43BB-947C-9F6C265D0699@gmail.com>
References <CAKUKWzmnnrpm-9SVNAFu3G9vYf2w0ewAhnGeOge8B2NsDujamQ@mail.gmail.com> <CAPTjJmrO7fER7Wjgo6qNO9qHNJgkJ7Y3BFWBf1L=t-bOv4JV7w@mail.gmail.com> <53F634E5.4020206@m4x.org> <mailman.13263.1408667169.18130.python-list@python.org> <0f0ef37d-7d09-483f-8f9b-c63c444f1ea7@googlegroups.com> <3DBE5DB0-3FA8-43BB-947C-9F6C265D0699@gmail.com>
Date Sat, 23 Aug 2014 06:32:41 +1000
Subject Re: Halfway point between interactive and daemon?
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.13308.1408739570.18130.python-list@python.org> (permalink)
Lines 43
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1408739570 news.xs4all.nl 2857 [2001:888:2000:d::a6]:54300
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:76822

Show key headers only | View raw


On Sat, Aug 23, 2014 at 5:27 AM, Travis Griggs <travisgriggs@gmail.com> wrote:
> I’m curious if there’s a technique one could use to get half way there. Basically, with minimal modifications, I’d like to get it running at startup.

Okay, hold on a minute there. There are two quite separate things
here: daemonization, and starting on system startup.

Daemonization is actually unnecessary to the latter, if you use a
modern init system. Just write your program to never fork, and either
Upstart or systemd will happily monitor it. Just create a unit file,
something like this:

[Unit]
Description=Yosemite Project
[Service]
Environment=DISPLAY=:0.0
User=whichever_user_to_run_as
ExecStart=/usr/bin/python /path/to/your/script
# If the network isn't available yet, restart until it is.
Restart=on-failure
RestartSec=10
[Install]
WantedBy=multi-user.target

$ systemctl --system daemon-reload
$ systemctl enable yos.service
$ systemctl start yos.service

(Feel free to steal that for your own purposes. It came from my
MIT-licensed videos server project "Yosemite".)

Daemonization should be optional. The above unit file works fine for
something that doesn't fork itself away. (I'm not sure how systemd
works with daemonizing processes, never tried. In any case, it's
unnecessary.) If you do need it (so the user can start your program
from the command line), I strongly recommend picking up a module off
PyPI; there are actually a lot of little details that people will
expect you to have gotten right. May as well bury it all away in a
little daemonize() call :)

ChrisA

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


Thread

Re: Python vs C++ Chris Angelico <rosuav@gmail.com> - 2014-08-22 10:26 +1000
  Re: Python vs C++ CHIN Dihedral <dihedral88888@gmail.com> - 2014-08-22 12:00 -0700
    Halfway point between interactive and daemon? Travis Griggs <travisgriggs@gmail.com> - 2014-08-22 12:27 -0700
      Re: Halfway point between interactive and daemon? Marko Rauhamaa <marko@pacujo.net> - 2014-08-22 22:49 +0300
    Re: Halfway point between interactive and daemon? Chris Angelico <rosuav@gmail.com> - 2014-08-23 06:32 +1000

csiph-web