You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When using force_polling=True and a watched file/directory is changed more than once in the same second, the change is not reported. I was expecting to receive an event for the change. It seems like the sub-second part of the mtime is being ignored.
Example Code
importasyncioimportpathlibimporttempfilefromdatetimeimportdatetimefromwatchfilesimportawatchasyncdefchange_config_file(config_file: pathlib.Path) ->None:
awaitasyncio.sleep(0.2)
config_file.write_text("World")
print("Modified file: mtime =", config_file.stat().st_ctime)
asyncdeftest(tmpdir: pathlib.Path) ->None:
"""Test the complete flow of configuration management."""config_file=tmpdir/"file.txt"config_file.write_text("Hello")
print("Created file: mtime =", config_file.stat().st_ctime)
task=asyncio.create_task(change_config_file(config_file))
try:
asyncwithasyncio.timeout(1):
# Watch the parent directory for changesprint(f"Started watching {config_file} at {datetime.now().timestamp()}")
asyncforchangesinawatch(
config_file, # Monitoring the parent directory has the issue toowatch_filter=None,
force_polling=True, # Not using polling makes this work finepoll_delay_ms=100,
):
forchange_type, changed_pathinchanges:
ifpathlib.Path(changed_path) ==config_file:
print(
f"<<< EVENT DETECTED >> at {datetime.now().timestamp()}: {change_type} - {changed_path}"
)
awaittaskreturn# Exit after first relevant change is detectedfinally:
task.cancel()
print(
f"Finished at {datetime.now().timestamp()}: mtime = {config_file.stat().st_ctime}"
)
if__name__=="__main__":
withtempfile.TemporaryDirectory() astmpdir:
try:
asyncio.run(test(pathlib.Path(tmpdir)))
exceptasyncio.TimeoutError:
print("<<< TIMEOUT REACHED >> (changes not detected)")
I tried reproducing this using notify-rs directly, and it seems to work fine, but I'm not a rust programmer, so maybe my test is wrong.
llucax
changed the title
Changes not detected if the file was changed more than once in the same second when using polling
Missed sub-second updates when using polling
Dec 19, 2024
Description
When using
force_polling=True
and a watched file/directory is changed more than once in the same second, the change is not reported. I was expecting to receive an event for the change. It seems like the sub-second part of the mtime is being ignored.Example Code
I tried reproducing this using
notify-rs
directly, and it seems to work fine, but I'm not a rust programmer, so maybe my test is wrong.This always work, even when the update is done on the same second.
Watchfiles Output
Operating System & Architecture
Environment
Tried on ext4 and tmpfs, both fail.
Python & Watchfiles Version
python: 3.11.10 (main, Sep 9 2024, 22:11:19) [Clang 18.1.8 ], watchfiles: 1.0.3
Rust & Cargo Version
cargo 1.83.0 (5ffbef321 2024-10-29) rustc 1.83.0 (90b35a623 2024-11-26)
The text was updated successfully, but these errors were encountered: