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

Watch not reacting inside of docker, but run_process does #225

Closed
Jim-Holmstroem opened this issue Apr 19, 2023 · 1 comment
Closed

Watch not reacting inside of docker, but run_process does #225

Jim-Holmstroem opened this issue Apr 19, 2023 · 1 comment
Labels

Comments

@Jim-Holmstroem
Copy link

Description

Having issue with the watch/awatch examples not generating changes inside of docker.
Tried with mounted file, mounted folder and a file inside of the container.
In the same environment watchfiles and run_process triggers as expected.
A raw-event is still logged (with debug=True) for watch/awatch, but nothing more happens

raw-event: Event { kind: Modify(Metadata(WriteTime)), paths: ["watch-this-folder/file"], attr:tracker: None, attr:flag: None, attr:info: None, attr:source: None }

Outside of docker all versions (see below) works as expected and all versions trigger on changes.

The same behavior is observed with both PollWatcher and INotifyWatcher (via WATCHFILES_FORCE_POLLING=1).

Example Code

The different examples and some docker to set up the environment:
https://github.com/Jim-Holmstroem/watch-issue

Run with

WATCH_THIS=watch-this-folder WATCHFILES_FORCE_POLLING=1 docker-compose up --build

Watchfiles Output

$ WATCH_THIS=watch-this-folder WATCHFILES_FORCE_POLLING=1 docker-compose up --build

watch-issue-watchfiles-1    | [18:34:31] watchfiles v0.19.0 __  path="/test/watch-this-folder" target="echo reloaded" (command) filter=DefaultFilter...
watch-issue-watchfiles-1    | [18:34:31] running "echo reloaded" as command
watch-issue-watchfiles-1    | watcher: PollWatcher { watches: Mutex { data: <locked>, poisoned: false, .. }, data_builder: Mutex { data: <locked>, poisoned: false, .. }, want_to_stop: false, delay: 300ms }
watch-issue-watchfiles-1    | reloaded
watch-issue-test-1          | watcher: PollWatcher { watches: Mutex { data: {"watch-this-folder": WatchData { root: "watch-this-folder", is_recursive: true, all_path_data: {"watch-this-folder/file": PathData { mtime: 1681929146, hash: None, last_check: Instant { tv_sec: 258857, tv_nsec: 375153812 } }, "watch-this-folder": PathData { mtime: 1681924805, hash: None, last_check: Instant { tv_sec: 258857, tv_nsec: 375153812 } }} }}, poisoned: false, .. }, data_builder: Mutex { data: DataBuilder { build_hasher: None, now: Instant { tv_sec: 258857, tv_nsec: 375153812 } }, poisoned: false, .. }, want_to_stop: false, delay: 300ms }
watch-issue-process-test-1  | watcher: PollWatcher { watches: Mutex { data: <locked>, poisoned: false, .. }, data_builder: Mutex { data: <locked>, poisoned: false, .. }, want_to_stop: false, delay: 300ms }
watch-issue-process-test-1  | changed
watch-issue-async-test-1    | watcher: PollWatcher { watches: Mutex { data: {"watch-this-folder": WatchData { root: "watch-this-folder", is_recursive: true, all_path_data: {"watch-this-folder": PathData { mtime: 1681924805, hash: None, last_check: Instant { tv_sec: 258857, tv_nsec: 424468683 } }, "watch-this-folder/file": PathData { mtime: 1681929146, hash: None, last_check: Instant { tv_sec: 258857, tv_nsec: 424468683 } }} }}, poisoned: false, .. }, data_builder: Mutex { data: <locked>, poisoned: false, .. }, want_to_stop: false, delay: 300ms }
watch-issue-watchfiles-1    | [18:34:36] rust notify timeout, continuing
watch-issue-watchfiles-1    | [18:34:41] rust notify timeout, continuing

...

$ echo "line" >> watch-this-folder/file

...

watch-issue-test-1          | raw-event: Event { kind: Modify(Metadata(WriteTime)), paths: ["watch-this-folder/file"], attr:tracker: None, attr:flag: None, attr:info: None, attr:source: None }
watch-issue-process-test-1  | raw-event: Event { kind: Modify(Metadata(WriteTime)), paths: ["watch-this-folder/file"], attr:tracker: None, attr:flag: None, attr:info: None, attr:source: None }
watch-issue-watchfiles-1    | raw-event: Event { kind: Modify(Metadata(WriteTime)), paths: ["/test/watch-this-folder/file"], attr:tracker: None, attr:flag: None, attr:info: None, attr:source: None }
watch-issue-async-test-1    | raw-event: Event { kind: Modify(Metadata(WriteTime)), paths: ["watch-this-folder/file"], attr:tracker: None, attr:flag: None, attr:info: None, attr:source: None }
watch-issue-process-test-1  | process already dead, exit code: 0
watch-issue-watchfiles-1    | [18:35:02] 1 change detected: {(<Change.modified: 2>, '/test/watch-this-folder/file')}
watch-issue-watchfiles-1    | [18:35:02] process already dead, exit code: 0
watch-issue-watchfiles-1    | reloaded
watch-issue-process-test-1  | changed

Operating System & Architecture

Linux-6.2.10-arch1-1-x86_64-with-glibc2.37
#1 SMP PREEMPT_DYNAMIC Fri, 07 Apr 2023 02:10:43 +0000

Environment

Docker version 23.0.3, build 3e7cbfdee1; Docker Compose version 2.17.2

Python & Watchfiles Version

python: 3.10.10 (main, Mar 5 2023, 22:26:53) [GCC 12.2.1 20230201], watchfiles: 0.19.0

Rust & Cargo Version

No response

@Jim-Holmstroem
Copy link
Author

Forgot that you have to print(..., flush=True) if you run inside of docker, so not a bug.
Tested it with print(..., flush=True) and everything works as expected.

Closing

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

1 participant