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

Sending repeated SIGINT (Ctrl-C) signals to watchmedo auto-restart exits without stopping the child process #543

Closed
bengotow opened this issue Mar 15, 2019 · 1 comment

Comments

@bengotow
Copy link

bengotow commented Mar 15, 2019

Hey folks! I've been using the watchmedo CLI to make a web server automatically restart when the contents of a directory change. Unfortunately we ran in to issues with this pretty quickly after launch because sending a SIGINT to watchmedo:

  1. Cleans up the file observers
  2. Sends a SIGINT to the child process

Step 1 takes about 500ms (at least on large directories like the one we're watching) and sending a second SIGINT in that time frame kills watchmedo without a SIGINT ever getting sent to the child.

If you're one of those keyboard bashing folks that hammers Ctrl-C, watchmedo basically never stops the child process when you kill it.

We've implemented a fix for this over here (dagster-io/dagster#930) that involves calling event_handler.stop() before cleaning up the file observers here: https://github.com/gorakhargosh/watchdog/blob/master/src/watchdog/watchmedo.py#L124. This might have undesirable side effects when observe_with is used in other modes (I'm not sure?) but it ensures that the child process is killed as soon as watchmedo receives a signal and it doesn't leave dangling processes.

Would a PR for this be mergeable?

@bengotow bengotow changed the title Sending repeated SIGINT (Ctrl-C) signals to watchmedo auto-restart does not stop the child process Sending repeated SIGINT (Ctrl-C) signals to watchmedo auto-restart exits without stopping the child process Mar 15, 2019
@BoboTiG
Copy link
Collaborator

BoboTiG commented Mar 24, 2019

Hello @bengotow,

Thanks for opening the issue. I think a PR would be mergeable, yes :)
(If you manager to add a simple test inside, it wold be great too!)

maybe-sybr added a commit to maybe-sybr/watchdog that referenced this issue Oct 20, 2020
This fixes misbehaviour where the child process could be orphaned if
watchmedo received multiple non-fatal signals causing the
`handler.stop()` call to be interrupted or never occur. By raising a
semantic exception after neutering the relevant signals, we give
ourselves a better chance of killing the child.

Fixes gorakhargosh#543
maybe-sybr added a commit to maybe-sybr/watchdog that referenced this issue Oct 21, 2020
This fixes misbehaviour where the child process could be orphaned if
watchmedo received multiple non-fatal signals causing the
`handler.stop()` call to be interrupted or never occur. By raising a
semantic exception after neutering the relevant signals, we give
ourselves a better chance of killing the child.

Fixes gorakhargosh#543
@BoboTiG BoboTiG added the bug label Oct 22, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants