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

Watcher prevents child processes from being killed #137

Open
Ehesp opened this issue Feb 7, 2023 · 2 comments
Open

Watcher prevents child processes from being killed #137

Ehesp opened this issue Feb 7, 2023 · 2 comments

Comments

@Ehesp
Copy link

Ehesp commented Feb 7, 2023

When using watcher (and typically the hotreloader package), processes never seem to be killed whilst watch events are being listened too. A minimal setup of this looks like:

Process process = await Process.start('some-long-lived-process');

final watcher = DirectoryWatcher(p.join(Directory.current.path, 'lib'));

watcher.events.listen((event) async {
  final result = process.exit();
  print(result); // true
});

Looking at activity monitor, the process spawned is never killed. I've tried a combination of signals, but upon investigation the process simply never exists whilst the watcher is active. This also includes trying to exist outside of the listener.

My current workaround is to kill the watcher on an event, kill the process and restart the flow. Something like:

while (true) {
  Process process = await Process.start('some-long-lived-process');

  final watcher = DirectoryWatcher(p.join(Directory.current.path, 'lib'));
  final completer = Completer();
  StreamSubscription? watcherSubscription;

  watcherSubscription = watcher.events.listen((event) async {
    if (!completer.isCompleted) completer.complete();
  });
 
  await completer.future; // wait for an event
  await watcherSubscription.cancel(); // stop the watcher
  process.kill(); // kill the process

  // while loop starts it again
}

Probably worth noting I'm on MacOS here.

@Solido
Copy link

Solido commented Feb 7, 2023

Maybe check that sdt out and error buffers are flushed?

@Ehesp
Copy link
Author

Ehesp commented Feb 7, 2023

Fairly sure I tried that, but will double check again and report back.

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

2 participants