joh / when-changed

Execute a command when a file is changed
Other
1.21k stars 107 forks source link

Add kill flag #85

Closed tom-doerr closed 7 months ago

tom-doerr commented 4 years ago

Attempt on adding #61 .

joh commented 2 years ago

Hi, first of all, my sincerest apologies for taking so long to review this!

I have tested your code, and it works nicely.

However, I noticed something strange when the -k switch is enabled: a file change event seems to be triggered twice, as opposed to without the switch:

$ when-changed -v file -c bash -c 'while sleep 1; do echo $$; done'
When 'file' changes, run 'bash -c while sleep 1; do echo $$; done'
==> '/home/joh/code/when-changed/file' modified <==
1544891
1544891
1544891
When 'file' changes, run 'bash -c while sleep 1; do echo $$; done'
==> '/home/joh/code/when-changed/file' modified <==
==> '/home/joh/code/when-changed/file' modified <==
1544989
1544989
1544989

Also, the code seems to rely on os.setsid, os.getpgid and os.killpg, which I believe are only available on POSIX systems (and not on Windows). Are there other ways to achieve the same which are cross-platform?

joh commented 7 months ago

@tom-doerr Do you plan to continue with this PR? Will close otherwise.

tom-doerr commented 7 months ago

Hi @joh, no, I can't remember what was going on in this PR