knadh / koanf

Simple, extremely lightweight, extensible, configuration management library for Go. Support for JSON, TOML, YAML, env, command line, file, S3 etc. Alternative to viper.
MIT License
2.55k stars 146 forks source link

watch function detects exceptions when python modifies a file #298

Closed ours1505 closed 7 hours ago

ours1505 commented 1 month ago

Describe the bug When I was modifying the configuration file using Python, two modifications were detected, the first one reading an empty file.

To Reproduce

with open('config.yml', 'r+') as file:
        data = yaml.safe_load(file)
        routes = data['config']['lite']['routes']
        for host in host_list:
            data['config']['lite']['routes'] = [route for route in routes if route.get('host') != host]
        file.seek(0) 
        file.truncate()
        yaml.dump(data, file, default_style=None)
        file.flush()

Expected behavior When I use Python to modify it, only one modification is detected

Please provide the following information):

knadh commented 2 weeks ago

I have updated the fsnotify lib that does the file watching to the latest version. Please pull the latest version (v1.0.0) of providers/file and retry.

PS: Internally, the file provider keeps a buffer of 5ms between two events to prevent duplicate events firing.