Watchdog: watchmedo detect file change but execute command twice

Created on 3 May 2018  路  3Comments  路  Source: gorakhargosh/watchdog

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

Most helpful comment

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

All 3 comments

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.

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.

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

Was this page helpful?
0 / 5 - 0 ratings

Related issues

bhargavrpatel picture bhargavrpatel  路  3Comments

alciomarhollanda picture alciomarhollanda  路  5Comments

TiagoOliveiraMarques picture TiagoOliveiraMarques  路  4Comments

thomasdot picture thomasdot  路  4Comments

fx86 picture fx86  路  3Comments