git » pymisc » commit bb86d4e

Implement pcmp.Channel.__del__ to close fds.

author Alberto Bertogli
2007-02-01 14:14:07 UTC
committer Alberto Bertogli
2007-02-01 14:14:07 UTC
parent 2cb6e28e7281cc64d9a878c796c5dd35b970a2c2

Implement pcmp.Channel.__del__ to close fds.

pcmp.py +10 -0

diff --git a/pcmp.py b/pcmp.py
index 546ef2c..16aa688 100644
--- a/pcmp.py
+++ b/pcmp.py
@@ -27,6 +27,16 @@ class Channel (object):
 		self._rfd = None
 		self._wfd = None
 
+	def __del__(self):
+		if self._rfd:
+			self._rfd.close()
+			self._wfd.close()
+		else:
+			os.close(self._p2c[0])
+			os.close(self._p2c[1])
+			os.close(self._c2p[0])
+			os.close(self._c2p[1])
+
 	def child(self):
 		"Tell the object we're the child."
 		self._wfd = os.fdopen(self._c2p[1], 'w')  # we write via p1.w