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
}
When using
watcher
(and typically thehotreloader
package), processes never seem to be killed whilst watch events are being listened too. A minimal setup of this looks like: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:
Probably worth noting I'm on MacOS here.