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


Groups > comp.lang.python > #88140

Re: What is elegant way to do configuration on server app

References <CAEKwp_FsbbAOrBm1h-CE1PS358pJBadJqNDi1CN7upC_s3nqCw@mail.gmail.com> <mailman.189.1427360350.10327.python-list@python.org> <mf19qa$ii6$2@reader1.panix.com>
Date 2015-03-27 16:28 +0800
Subject Re: What is elegant way to do configuration on server app
From Jerry OELoo <oyljerry@gmail.com>
Newsgroups comp.lang.python
Message-ID <mailman.236.1427444902.10327.python-list@python.org> (permalink)

Show all headers | View raw


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 <invalid@invalid.invalid> wrote:
> On 2015-03-26, Ben Finney <ben+python@benfinney.id.au> wrote:
>> Jerry OELoo <oyljerry@gmail.com> 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
>>  <URL:https://docs.python.org/3/library/configparser.html> 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
>>  <URL:https://docs.python.org/3/library/os.html#os.stat_result.st_mtime>.
>>
>>   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.
> --
> https://mail.python.org/mailman/listinfo/python-list



-- 
Rejoice,I Desire!

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


Thread

Re: What is elegant way to do configuration on server app Ben Finney <ben+python@benfinney.id.au> - 2015-03-26 19:59 +1100
  Re: What is elegant way to do configuration on server app Grant Edwards <invalid@invalid.invalid> - 2015-03-26 15:49 +0000
    Re: What is elegant way to do configuration on server app Jerry OELoo <oyljerry@gmail.com> - 2015-03-27 16:28 +0800
      Re: What is elegant way to do configuration on server app Grant Edwards <invalid@invalid.invalid> - 2015-03-27 16:28 +0000
        Re: What is elegant way to do configuration on server app Chris Angelico <rosuav@gmail.com> - 2015-03-28 03:36 +1100
          Re: What is elegant way to do configuration on server app Grant Edwards <invalid@invalid.invalid> - 2015-03-27 16:44 +0000
    Re: What is elegant way to do configuration on server app Marko Rauhamaa <marko@pacujo.net> - 2015-03-27 10:47 +0200
      Re: What is elegant way to do configuration on server app Chris Angelico <rosuav@gmail.com> - 2015-03-28 00:12 +1100
        Re: What is elegant way to do configuration on server app Marko Rauhamaa <marko@pacujo.net> - 2015-03-27 15:23 +0200
          Re: What is elegant way to do configuration on server app Chris Angelico <rosuav@gmail.com> - 2015-03-28 00:34 +1100
      Re: What is elegant way to do configuration on server app Grant Edwards <invalid@invalid.invalid> - 2015-03-27 16:30 +0000
        Re: What is elegant way to do configuration on server app Marko Rauhamaa <marko@pacujo.net> - 2015-03-27 18:44 +0200

csiph-web