Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

awatch on a file on Linux trigger delete event #259

Closed
hoxbro opened this issue Feb 7, 2024 · 4 comments
Closed

awatch on a file on Linux trigger delete event #259

hoxbro opened this issue Feb 7, 2024 · 4 comments
Labels

Comments

@hoxbro
Copy link

hoxbro commented Feb 7, 2024

Description

When running the example code below on Linux, I get a delete event right after the file is changed and saved. After the delete event, the file is removed from the watched files, and nothing happens during the next save.

This does not happen on a Mac (I haven't tested on Windows).

Example Code

import asyncio
from watchfiles import awatch

async def main():
    async for changes in awatch('example.py', debug=True):
        print(changes)

asyncio.run(main())

Watchfiles Output

# On Linux:
watcher: INotifyWatcher { channel: Sender { .. }, waker: Waker { inner: Waker { fd: File { fd: 9, path: "anon_inode:[eventfd]", read: true, write: true } } } }
raw-event=Access(Close(Write)) event.kind=Access(Close(Write)) no change detected
raw-event=Event { kind: Modify(Metadata(Any)), paths: ["/home/shh/projects/holoviz/repos/panel/example.py"], attr:tracker: None, attr:flag: None, attr:info: None, attr:source: None } change=2
raw-event=Event { kind: Remove(File), paths: ["/home/shh/projects/holoviz/repos/panel/example.py"], attr:tracker: None, attr:flag: None, attr:info: None, attr:source: None } change=3
{(<Change.modified: 2>, '/home/shh/projects/holoviz/repos/panel/example.py'), (<Change.deleted: 3>, '/home/shh/projects/holoviz/repos/panel/example.py')}

# On Mac
watcher: FsEventWatcher { paths: 0x600000f846c0, since_when: 18446744073709551615, latency: 0.0, flags: 18, event_handler: 0x60000149c310, runloop: Some((0x6000034880c0, JoinHandle { .. })), recursive_info: {"/Users/shh/Downloads/example.py": true} }
raw-event=Event { kind: Modify(Name(Any)), paths: ["/Users/shh/Downloads/example.py"], attr:tracker: None, attr:flag: None, attr:info: None, attr:source: None } change=1
raw-event=Event { kind: Modify(Name(Any)), paths: ["/Users/shh/Downloads/example.py"], attr:tracker: None, attr:flag: None, attr:info: None, attr:source: None } change=1
{(<Change.added: 1>, '/Users/shh/Downloads/example.py')}
raw-event=Event { kind: Modify(Name(Any)), paths: ["/Users/shh/Downloads/example.py"], attr:tracker: None, attr:flag: None, attr:info: None, attr:source: None } change=1
raw-event=Event { kind: Modify(Name(Any)), paths: ["/Users/shh/Downloads/example.py"], attr:tracker: None, attr:flag: None, attr:info: None, attr:source: None } change=1
{(<Change.added: 1>, '/Users/shh/Downloads/example.py')}
raw-event=Event { kind: Modify(Name(Any)), paths: ["/Users/shh/Downloads/example.py"], attr:tracker: None, attr:flag: None, attr:info: None, attr:source: None } change=1
raw-event=Event { kind: Modify(Name(Any)), paths: ["/Users/shh/Downloads/example.py"], attr:tracker: None, attr:flag: None, attr:info: None, attr:source: None } change=1
{(<Change.added: 1>, '/Users/shh/Downloads/example.py')}
raw-event=Event { kind: Modify(Name(Any)), paths: ["/Users/shh/Downloads/example.py"], attr:tracker: None, attr:flag: None, attr:info: None, attr:source: None } change=1
raw-event=Event { kind: Modify(Name(Any)), paths: ["/Users/shh/Downloads/example.py"], attr:tracker: None, attr:flag: None, attr:info: None, attr:source: None } change=1
{(<Change.added: 1>, '/Users/shh/Downloads/example.py')}
raw-event=Event { kind: Modify(Name(Any)), paths: ["/Users/shh/Downloads/example.py"], attr:tracker: None, attr:flag: None, attr:info: None, attr:source: None } change=1
raw-event=Event { kind: Modify(Name(Any)), paths: ["/Users/shh/Downloads/example.py"], attr:tracker: None, attr:flag: None, attr:info: None, attr:source: None } change=1
{(<Change.added: 1>, '/Users/shh/Downloads/example.py')}

Operating System & Architecture

On Linux

Linux-6.6.10-76060610-generic-x86_64-with-glibc2.35
#202401051437170472813122.04~24d69e2 SMP PREEMPT_DYNAMIC Mon J

On Mac

macOS-14.2.1-arm64-arm-64bit
Darwin Kernel Version 23.2.0: Wed Nov 15 21:53:34 PST 2023; root:xnu-10002.61.3~2/RELEASE_ARM64_T8103

Environment

No response

Python & Watchfiles Version

python: 3.11.7 | packaged by conda-forge | (main, Dec 23 2023, 14:43:09) [GCC 12.3.0], watchfiles: 0.21.0 || python: 3.11.6 | packaged by conda-forge | (main, Oct 3 2023, 10:37:07) [Clang 15.0.7 ], watchfiles: 0.21.0

Rust & Cargo Version

No response

@hoxbro hoxbro added the bug label Feb 7, 2024
@hoxbro
Copy link
Author

hoxbro commented Feb 7, 2024

It seems to be because the apps I used on Linux use a buffer and then overwrite the file.

The apps where it is a problem are Neovim and Gnome TextEditor. It does not seem to be a problem with VSCode.

@hoxbro
Copy link
Author

hoxbro commented Feb 8, 2024

A duplicate of #235

@hoxbro hoxbro closed this as completed Feb 8, 2024
@samuelcolvin
Copy link
Owner

👍 thanks for reporting, and following up.

@hoxbro
Copy link
Author

hoxbro commented Feb 8, 2024

No problem. The underlying issue is notify-rs/notify#247.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants