Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!nntp.club.cc.cmu.edu!micro-heart-of-gold.mit.edu!bloom-beacon.mit.edu!bloom-beacon.mit.edu!panix!not-for-mail From: Grant Edwards Newsgroups: comp.lang.python Subject: Re: What is elegant way to do configuration on server app Date: Thu, 26 Mar 2015 15:49:30 +0000 (UTC) Organization: PANIX Public Access Internet and UNIX, NYC Lines: 42 Message-ID: References: NNTP-Posting-Host: 67-130-15-94.dia.static.qwest.net Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Trace: reader1.panix.com 1427384970 19014 67.130.15.94 (26 Mar 2015 15:49:30 GMT) X-Complaints-To: abuse@panix.com NNTP-Posting-Date: Thu, 26 Mar 2015 15:49:30 +0000 (UTC) User-Agent: slrn/1.0.1 (Linux) Xref: csiph.com comp.lang.python:88073 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 ‘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. 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 “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. 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 ANOTHER gmail.com WORLD all THE DAYS OF OUR LIVES.