When you pass the write pipe to Popen to catch its stderr to logs, you can immediately close the pipe- your Popen process has already opened it, it will be preserved.
This way, you don't have to do it during close(), which is already complex enough.
In general, all Popen calls can be set to bias against passing unneeded pipes and needed pipes can be passed explicitly to reduce kernel resource leaks.