I am reading configurations from an ini file using Python configparser. 95% of the time, it works perfectly. Without any changes to the ini file (e.g., in the middle of a regression test), configparser will start returning empty results, and then of course have key errors as it searches for nested configs.
This suggests it is not a problem with the ini file, since it is not changing, and also because it happens occasionally. Once the problem happens, it continues to happen across all calls to config parser until i kill the program and re-run it.
I'm reading the config as such:
try:
path = os.path.dirname(os.path.realpath(__file__))
kml_ini = '/'.join([path, 'kml.ini'])
config = configparser.ConfigParser()
config.read(kml_ini)
db_conn_returnable = config['database']['db_connection'].strip()
except Exception as e:
print(e)
traceback.print_exc(file=sys.stdout)
pprint.pprint(config.sections())
pprint.pprint({section: dict(config.items(section)) for section in config.sections()})
I'm getting the error: File "/home/sahmed/anaconda3/envs/kml/lib/python3.6/configparser.py", line 959, in getitem KeyError: 'database'
My ini file looks as such:
[api]
server_debug=False
log_level=info
n_workers=10
[database]
db_connection=http://1.1.1.1:9191
user=admin
pass=whateverman
[cluster]
default_workers=3
My original thought was a thread issue since I've got 8 threads hitting this config file constantly (though it doesnt make sense...we're reading only) so I even put a fasteners block on the read, still no luck. What might cause such a situation?