Path: csiph.com!usenet.pasdenom.info!weretis.net!feeder4.news.weretis.net!news.mixmin.net!feeder1.xsusenet.com!newsfeed.xs4all.nl!newsfeed2a.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.001 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'value,': 0.04; 'configure': 0.05; 'currently,': 0.09; 'executable': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'subject:skip:c 10': 0.09; 'runs': 0.10; 'python': 0.11; '(assuming': 0.16; 'advice:': 0.16; 'comparisons,': 0.16; 'finney': 0.16; 'helps.': 0.16; 'newer,': 0.16; 're-read': 0.16; 'received:80.91.229.3': 0.16; 'received:plane.gmane.org': 0.16; 'resist': 0.16; 'simpler,': 0.16; 'tempted': 0.16; 'timestamp': 0.16; 'modification': 0.16; 'library': 0.18; 'module': 0.19; 'file,': 0.19; "python's": 0.19; 'header:User-Agent:1': 0.23; 'config': 0.24; 'parse': 0.24; 'fine': 0.24; 'values': 0.27; 'header:X -Complaints-To:1': 0.27; 'record': 0.27; 'changed.': 0.31; 'convenience': 0.31; 'values.': 0.31; 'writes:': 0.31; 'file': 0.32; 'url:python': 0.33; '(e.g.': 0.33; 'common': 0.35; 'format.': 0.36; 'url:org': 0.36; 'seconds': 0.37; 'server': 0.38; 'ben': 0.38; 'url:library': 0.38; 'to:addr:python-list': 0.38; 'to:addr:python.org': 0.39; 'received:org': 0.40; 'read': 0.60; 'future': 0.60; 'hope': 0.61; 'url:3': 0.61; 'skip:n 10': 0.64; 'provide': 0.64; 'skip:\xe2 10': 0.65; 'received:125': 0.84; 'start.': 0.84; 'url:configparser': 0.84; 'wakes': 0.84; '8bit%:33': 0.91; 'hong': 0.91; 'kong': 0.91 X-Injected-Via-Gmane: http://gmane.org/ To: python-list@python.org From: Ben Finney Subject: Re: What is elegant way to do configuration on server app Date: Thu, 26 Mar 2015 19:59:13 +1100 References: Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Gmane-NNTP-Posting-Host: jigong.madmonks.org X-Public-Key-ID: 0xAC128405 X-Public-Key-Fingerprint: 517C F14B B2F3 98B0 CB35 4855 B8B2 4C06 AC12 8405 X-Public-Key-URL: http://www.benfinney.id.au/contact/bfinney-pubkey.asc X-Post-From: Ben Finney User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.4 (gnu/linux) Cancel-Lock: sha1:od7J/16i4GexCF0ONk02LgaDXic= 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: 34 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1427360350 news.xs4all.nl 2978 [2001:888:2000:d::a6]:42172 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:88034 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 ‘configparser’ module to parse and provide the values from a very common configuration file format. Use that unless you have a good reason not to. * Your program can “poll” 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. Hope that helps. -- \ “For your convenience we recommend courteous, efficient | `\ self-service.” —supermarket, Hong Kong | _o__) | Ben Finney