Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #88034
| From | Ben Finney <ben+python@benfinney.id.au> |
|---|---|
| Subject | Re: What is elegant way to do configuration on server app |
| Date | 2015-03-26 19:59 +1100 |
| References | <CAEKwp_FsbbAOrBm1h-CE1PS358pJBadJqNDi1CN7upC_s3nqCw@mail.gmail.com> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.189.1427360350.10327.python-list@python.org> (permalink) |
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. * 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. Hope that helps. -- \ “For your convenience we recommend courteous, efficient | `\ self-service.” —supermarket, Hong Kong | _o__) | Ben Finney
Back to comp.lang.python | Previous | Next — Next in thread | Find similar | Unroll 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