author | Alberto Bertogli
<albertito@gmail.com> 2007-02-01 14:14:32 UTC |
committer | Alberto Bertogli
<albertito@gmail.com> 2007-02-01 14:14:32 UTC |
parent | bb86d4ecf305b5e1e5a8096474a23f87cb0a2b85 |
pcmp.py | +12 | -4 |
diff --git a/pcmp.py b/pcmp.py index 16aa688..4bf76a3 100644 --- a/pcmp.py +++ b/pcmp.py @@ -39,13 +39,21 @@ class Channel (object): def child(self): "Tell the object we're the child." - self._wfd = os.fdopen(self._c2p[1], 'w') # we write via p1.w - self._rfd = os.fdopen(self._p2c[0], 'r') # and read via p2.r + # write via p1.w, read via p2.r, and close unnecessary fds + # (see man 7 pipe) + self._wfd = os.fdopen(self._c2p[1], 'w') + self._rfd = os.fdopen(self._p2c[0], 'r') + os.close(self._c2p[0]) + os.close(self._p2c[1]) def parent(self): "Tell the object we're the parent." - self._wfd = os.fdopen(self._p2c[1], 'w') # we write via p2.w - self._rfd = os.fdopen(self._c2p[0], 'r') # we read via p1.r + # write via p2.w, read via p1.r, and close unnecessary fds + # (see man 7 pipe) + self._wfd = os.fdopen(self._p2c[1], 'w') + self._rfd = os.fdopen(self._c2p[0], 'r') + os.close(self._p2c[0]) + os.close(self._c2p[1]) def send(self, o): "Send an object."