bpo-37137: Close pid waiters on watcher.close() by asvetlov · Pull Request #13792 · python/cpython

I'm not sure this is correct... isn't it allowed to start a process through asyncio, and then for the parent process to exit and leave the child running?

In trio we use the threaded strategy, and we make it a daemon thread and if the trio loop exits, oh well, the thread won't outlive either the host process or the watched process, so it's OK to leak it.

To solve the test failures, maybe it's enough to say: the child process should be exited before the test finishes, and if the test waits to see that the child process has exited, then it's guaranteed that the thread has exited too. (If you want to be extra-certain, then the code that handles the child process notification in the main thread could call thread.join(). This is safe because it knows that the thread will exit within the next few milliseconds at worst, and makes sure that the Python threading infrastructure has also noticed that the thread has exited.)