python3.2 fixes: ResourceWarning: unclosed file
authorZac Medico <zmedico@gentoo.org>
Thu, 25 Aug 2011 22:10:52 +0000 (15:10 -0700)
committerZac Medico <zmedico@gentoo.org>
Thu, 25 Aug 2011 22:10:52 +0000 (15:10 -0700)
pym/_emerge/AsynchronousLock.py

index 637ba7381e2c73b8fe9b39811ca745e0a648e97e..be498b802fca833c29e0803988a809fe309c6bdf 100644 (file)
@@ -209,9 +209,22 @@ class _LockProcess(AbstractPollTask):
                os.close(in_pw)
 
        def _proc_exit(self, proc):
+
+               if self._files is not None:
+                       # Close pipe_out if it's still open, since it's useless
+                       # after the process has exited. This helps to avoid
+                       # "ResourceWarning: unclosed file" since Python 3.2.
+                       try:
+                               pipe_out = self._files.pop('pipe_out')
+                       except KeyError:
+                               pass
+                       else:
+                               pipe_out.close()
+
                if proc.returncode != os.EX_OK:
                        # Typically, this will happen due to the
                        # process being killed by a signal.
+
                        if not self._acquired:
                                # If the lock hasn't been aquired yet, the
                                # caller can check the returncode and handle