From a509ffd891642b3353a6160ba04057272b48dc2c Mon Sep 17 00:00:00 2001 From: Zac Medico Date: Thu, 25 Aug 2011 15:10:52 -0700 Subject: [PATCH] python3.2 fixes: ResourceWarning: unclosed file --- pym/_emerge/AsynchronousLock.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/pym/_emerge/AsynchronousLock.py b/pym/_emerge/AsynchronousLock.py index 637ba7381..be498b802 100644 --- a/pym/_emerge/AsynchronousLock.py +++ b/pym/_emerge/AsynchronousLock.py @@ -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 -- 2.26.2