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 auto-restart behavior change with 2.1.9 #922

Closed
jaycle opened this issue Oct 5, 2022 · 6 comments · Fixed by #946
Closed

watchmedo auto-restart behavior change with 2.1.9 #922

jaycle opened this issue Oct 5, 2022 · 6 comments · Fixed by #946

Comments

@jaycle
Copy link

jaycle commented Oct 5, 2022

We were using watchmedo auto-restart to call mypy and some flake8 tooling upon file changes. With the changes introduced by #896, these processes re-run continually every time they exit whereas before they were re-ran upon a watched file/directory change.

The name auto-restart makes me believe that this is actually desirable behavior and perhaps we were misusing that sub-command, however there doesn't appear to be an alternative to get the behavior we once had. watchmedo shell-command only runs the command on change with no option to run it once and also upon watched file change.

Is there a way to add a flag to auto-restart which only restarts on an exit code, or maybe a way to use shell-command to call the command initially and then repeat on a file change?

@taleinat
Copy link
Contributor

taleinat commented Jan 29, 2023

This seems like it would be very simple to implement with a script, which would run the tools once initially and then call watchmedo shell-command .... I'm not sure it's worth changing watchmedo to support it.

BTW, this seems like a great use-case for grouping together multiple events happening in a short time-frame ("debouncing") and launching the command only after that, similar to #542. This was implemented for watchmedo auto-restart in PR #940. If you'd like this for watchmedo shell-command too, consider creating an issue requesting that!

@adamzev
Copy link

adamzev commented Feb 21, 2023

Running the tools once initially and then calling watchmedo shell-command doesn't produce equivalent behavior for our use case. watchmedo auto-restart is often recommended to relaunch celery on file changes. However with the changes introduced by #896 it continually restart on errors (which causes issues with our error logs getting flooded). If we launch celery and then call watchmedo shell-command it wouldn't be able to restart celery for us since that was started separately. I'm sure we could create workarounds for this but not with the same simplicity as before.

Could we get a flag to disable (or enable, depending on what you want as the default) the following two lines?

# src/watchdog/tricks/__init__.py
self.process_watcher = ProcessWatcher(self.process, self._restart)
self.process_watcher.start()

@taleinat
Copy link
Contributor

@BoboTiG WDYT? We could add a flag for the trick and the CLI command.

@BoboTiG
Copy link
Collaborator

BoboTiG commented Feb 22, 2023

@taleinat yup, that would be a simple solution 👍

@BoboTiG
Copy link
Collaborator

BoboTiG commented Feb 22, 2023

Thanks a lot @taleinat !

I'll see to cut a new release in the week.

@BoboTiG
Copy link
Collaborator

BoboTiG commented Feb 23, 2023

v2.3.0 is out 🍾

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

Successfully merging a pull request may close this issue.

4 participants