Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!bcyclone04.am1.xlned.com!bcyclone04.am1.xlned.com!newsfeed.xs4all.nl!newsfeed4.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.018 X-Spam-Evidence: '*H*': 0.96; '*S*': 0.00; 'value,': 0.04; 'configure': 0.05; 'currently,': 0.09; 'executable': 0.09; 'subject:skip:c 10': 0.09; 'runs': 0.10; 'cc:addr:python-list': 0.11; 'python': 0.11; '(assuming': 0.16; 'advice:': 0.16; 'comparisons,': 0.16; 'finney': 0.16; 'json,': 0.16; 'newer,': 0.16; 're-read': 0.16; 'resist': 0.16; 'simpler,': 0.16; 'tempted': 0.16; 'timestamp': 0.16; 'modification': 0.16; 'wrote:': 0.18; 'library': 0.18; 'module': 0.19; 'file,': 0.19; "python's": 0.19; 'thu,': 0.19; '>>>': 0.22; 'cc:addr:python.org': 0.22; 'config': 0.24; 'parse': 0.24; 'fine': 0.24; 'cc:2**0': 0.24; 'cc:no real name:2**0': 0.24; 'second': 0.26; 'values': 0.27; 'gets': 0.27; 'header:In-Reply-To:1': 0.27; 'record': 0.27; '(this': 0.29; 'unix': 0.29; 'message-id:@mail.gmail.com': 0.30; 'url:mailman': 0.30; 'code': 0.31; 'changed.': 0.31; 'moderate': 0.31; 'values.': 0.31; 'writes:': 0.31; 'file': 0.32; 'stuff': 0.32; 'another': 0.32; 'url:python': 0.33; '(e.g.': 0.33; 'plain': 0.33; 'common': 0.35; 'something': 0.35; 'but': 0.35; 'received:google.com': 0.35; 'format.': 0.36; 'url:listinfo': 0.36; 'url:org': 0.36; 'seconds': 0.37; 'too': 0.37; 'implement': 0.38; 'server': 0.38; 'thank': 0.38; 'ben': 0.38; 'url:library': 0.38; 'handle': 0.38; 'pm,': 0.38; 'rather': 0.38; 'does': 0.39; 'url:mail': 0.40; 'days': 0.60; 'even': 0.60; 'read': 0.60; 'future': 0.60; 'url:3': 0.61; 'simple': 0.61; 'you.': 0.62; 'skip:n 10': 0.64; 'our': 0.64; 'provide': 0.64; 'more': 0.64; 'situation': 0.65; 'skip:\xe2 10': 0.65; 'life': 0.66; 'world': 0.66; 'mar': 0.68; '26,': 0.68; '2015': 0.84; 'configparser': 0.84; 'start.': 0.84; 'url:configparser': 0.84; 'wakes': 0.84; '8bit%:33': 0.91; 'edwards': 0.91 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:to :cc:content-type:content-transfer-encoding; bh=OmYXf/ZThpTkisWwuQKubVPO3dDexTTv1mMKaYNZWdA=; b=wFBDP986MPlf4YEfzux6+dx63yqGUJZ27QxnXHpwPKykq8KAjpW1L/fQxfRxn+lLoI g2WaDjH+aW3klJ3BLpUHqcTkZs98+Hcz8xH7uyCXeLXT5VDTh6JJzQk5sTZHkheMFOOb xFNhHO7Gx1hNOnCPATMQ+WHBCJkzQ0My9b2XUKTDWP+hrAc9wf1cwbx6hIGUx04lPjM3 IlpUlvQDSWRqZVM01TBFTOiqD+SFH01RiW0grNbWLcNpy+nuONtTsDsL5icMkW+jU6E2 Q03jYd87W2riS6t2DJcOIUAuxL/bTqbnPy+IQyh3wKui13JVKlowMelIqKQg0osUBFv5 PBtQ== MIME-Version: 1.0 X-Received: by 10.112.141.106 with SMTP id rn10mr17072684lbb.100.1427444895581; Fri, 27 Mar 2015 01:28:15 -0700 (PDT) In-Reply-To: References: Date: Fri, 27 Mar 2015 16:28:15 +0800 Subject: Re: What is elegant way to do configuration on server app From: Jerry OELoo To: Grant Edwards Cc: 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.19 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 60 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1427444902 news.xs4all.nl 2885 [2001:888:2000:d::a6]:37537 X-Complaints-To: abuse@xs4all.nl X-Received-Bytes: 6724 X-Received-Body-CRC: 730455613 Xref: csiph.com comp.lang.python:88140 Hi Grant: Why use SIGHUP, Does it has something to do with configure file modification? I don't get it. Thank you. On Thu, Mar 26, 2015 at 11:49 PM, Grant Edwards w= rote: > On 2015-03-26, Ben Finney wrote: >> Jerry OELoo writes: >> >>> Currently, I can just think out that I put status into a configure >>> file, and service schedule read this file and get status value, >> >> That sounds like a fine start. Some advice: >> >> * You may be tempted to make the configuration file executable (e.g. >> Python code). Resist that temptation; keep it *much* simpler, a >> non-executable data format. >> >> Python's standard library has the =E2=80=98configparser=E2=80=99 modul= e >> to parse and >> provide the values from a very common configuration file format. >> Use that unless you have a good reason not to. > > I second the recommendation for configparser for stuff of simple to > moderate complexity. If it gets too complex for configparser, you may > want to consider JSON, or for even more complex stuff just use plain > Python code in your config file (this can be very powerful and > expressive, but can also be diffucult to implement safely). > >> * Your program can =E2=80=9Cpoll=E2=80=9D the configuration file to see = whether it has >> changed. At startup, read the config file's modification timestamp >> = . >> >> Make a part of your event loop (assuming your server runs an event >> loop) that wakes up every N seconds (e.g. every 60 seconds) and >> checkes the file's modification timestamp again; if it's newer, record >> that value for future comparisons, then re-read the file for its >> values. > > That sounds rather Windowsesque. The more-or-less standard way to do > handle the situation on Unix is to reread the config file when you get > a SIGHUP. > > -- > Grant Edwards grant.b.edwards Yow! ONE LIFE TO LIVE = for > at ALL MY CHILDREN in ANO= THER > gmail.com WORLD all THE DAYS OF > OUR LIVES. > -- > https://mail.python.org/mailman/listinfo/python-list --=20 Rejoice,I Desire!