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

watchmedo detect file change but execute command twice #446

Open
gilles380 opened this issue May 3, 2018 · 3 comments
Open

watchmedo detect file change but execute command twice #446

gilles380 opened this issue May 3, 2018 · 3 comments

Comments

@gilles380
Copy link

Hi,

I try this simple example :

watchmedo shell-command --patterns="*.bin" --command 'copytoserver.bat'

which works quite well : when a .bin is created on the current directory, copytoserver.bat is executed TWICE, not just ONCE

Is it an issue or I am missing something in probiding good arguments ?

Thanks for help

Gilles

@danilobellini
Copy link
Collaborator

Indeed, that's happening.

On Linux, a simple touch filename would emit 2 messages: a file creation and a file modification, if the file doesn't exist. Probably the same is happening in Windows, and that's why it's running twice instead of once.

Saving it on vim here with some arbitrary made it run 11 times. Probably that's because it's including file deletion, temporary file creation and renaming.

@danilobellini
Copy link
Collaborator

Probably it would be better to split this project into 2: the library (watchdog) and the shell application (watchmedo). I'm not aware how many users relies on both, but perhaps the event filtering shouldn't be the same on both, and that might become a burden to maintain.

I've fixed this issue on dose by adding a single runner with a "debouncer" that:

  • Waits for $10 ms$ before starting the triggered job
  • Ignores new events during the next $50 ms$
  • Kills/restarts the job when a new event comes after that $50 ms$

Actually, that was so fast that used to break watchdog on Linux due to a strange event happening on a deleted directory, so I fixed it upstream.

But, that's an issue regarding a single runner triggered by an event. It's an application (like the watchmedo shell-command command). If we wanted to have distinct actions for distinct events, with some of them perhaps running in parallel, filtering out the events that happen to be close in time would be a mistake. That said, the problem isn't in the watchdog library, but in watchmedo.

@rtxanson
Copy link

rtxanson commented Feb 4, 2019

I had the same problem, and a quick workaround was to use flock -n test.lock CMD to make sure the process could only run once

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

No branches or pull requests

3 participants