diff options
author | Richard Maw <richard.maw@codethink.co.uk> | 2014-08-29 17:48:58 +0000 |
---|---|---|
committer | Richard Maw <richard.maw@codethink.co.uk> | 2014-08-29 17:48:58 +0000 |
commit | e96c6ee5591d252f70abae3355a35b31651fe988 (patch) | |
tree | 2ea1a8540048aa3a30188ec248c1b386a6c3059f | |
parent | 12b98200a1c3c864a27df644bf0b2e0f468a7fc3 (diff) | |
download | morph-e96c6ee5591d252f70abae3355a35b31651fe988.tar.gz |
Handle closing the ends of the log pipe we don't care aboutbaserock/richardmaw/deploy-improvements
We only need the read end in the parent, and we only need the write end
in the child, so we can close them pre-emptively.
Also, we need to close the write end in the parent so that when the
subprocess terminates we get EOF on the read end of the pipe.
-rw-r--r-- | morphlib/plugins/deploy_plugin.py | 13 |
1 files changed, 11 insertions, 2 deletions
diff --git a/morphlib/plugins/deploy_plugin.py b/morphlib/plugins/deploy_plugin.py index da72f91b..e4968736 100644 --- a/morphlib/plugins/deploy_plugin.py +++ b/morphlib/plugins/deploy_plugin.py @@ -570,14 +570,23 @@ class DeployPlugin(cliapp.Plugin): new_env = env.copy() new_env['MORPH_LOG_FD'] = str(log_write_fd) + # We lack python3's pass_fds to close any of the fds + # we don't care about, such as the read end of the log, + # so we have to close it ourselves here. + def close_read_end(): + os.close(log_read_fd) p = subprocess.Popen( [ext_filename] + args, cwd=gd.dirname, env=new_env, - stdout=subprocess.PIPE, stderr=subprocess.PIPE) + stdout=subprocess.PIPE, stderr=subprocess.PIPE, + preexec_fn=close_read_end) + os.close(log_write_fd) + log_write_fd = -1 self._watch_extension_subprocess(name, kind, p, log_read_fd) finally: os.close(log_read_fd) - os.close(log_write_fd) + if log_write_fd != -1: + os.close(log_write_fd) def _watch_extension_subprocess(self, name, kind, p, log_read_fd): '''Follow stdout, stderr and log output of an extension subprocess.''' |