From mboxrd@z Thu Jan  1 00:00:00 1970
Received: from pigeon.gentoo.org ([208.92.234.80] helo=lists.gentoo.org)
	by finch.gentoo.org with esmtp (Exim 4.60)
	(envelope-from <gentoo-commits+bounces-404492-garchives=archives.gentoo.org@lists.gentoo.org>)
	id 1RWIAl-0002nJ-PO
	for garchives@archives.gentoo.org; Fri, 02 Dec 2011 01:44:20 +0000
Received: from pigeon.gentoo.org (localhost [127.0.0.1])
	by pigeon.gentoo.org (Postfix) with SMTP id 1448B21C030;
	Fri,  2 Dec 2011 01:44:11 +0000 (UTC)
Received: from smtp.gentoo.org (smtp.gentoo.org [140.211.166.183])
	by pigeon.gentoo.org (Postfix) with ESMTP id C1D0021C030
	for <gentoo-commits@lists.gentoo.org>; Fri,  2 Dec 2011 01:44:10 +0000 (UTC)
Received: from pelican.gentoo.org (unknown [66.219.59.40])
	(using TLSv1 with cipher AECDH-AES256-SHA (256/256 bits))
	(No client certificate requested)
	by smtp.gentoo.org (Postfix) with ESMTPS id 3AEA21B4005
	for <gentoo-commits@lists.gentoo.org>; Fri,  2 Dec 2011 01:44:10 +0000 (UTC)
Received: from localhost.localdomain (localhost [127.0.0.1])
	by pelican.gentoo.org (Postfix) with ESMTP id 7EBDD80044
	for <gentoo-commits@lists.gentoo.org>; Fri,  2 Dec 2011 01:44:09 +0000 (UTC)
From: "Zac Medico" <zmedico@gentoo.org>
To: gentoo-commits@lists.gentoo.org
Content-type: text/plain; charset=UTF-8
Reply-To: gentoo-dev@lists.gentoo.org, "Zac Medico" <zmedico@gentoo.org>
Message-ID: <27b6a21bd8b4f9372c328b979ee0ba0a8020a2b9.zmedico@gentoo>
Subject: [gentoo-commits] proj/portage:master commit in: pym/_emerge/
X-VCS-Repository: proj/portage
X-VCS-Files: pym/_emerge/AsynchronousLock.py
X-VCS-Directories: pym/_emerge/
X-VCS-Committer: zmedico
X-VCS-Committer-Name: Zac Medico
X-VCS-Revision: 27b6a21bd8b4f9372c328b979ee0ba0a8020a2b9
Date: Fri,  2 Dec 2011 01:44:09 +0000 (UTC)
Precedence: bulk
List-Post: <mailto:gentoo-commits@lists.gentoo.org>
List-Help: <mailto:gentoo-commits+help@lists.gentoo.org>
List-Unsubscribe: <mailto:gentoo-commits+unsubscribe@lists.gentoo.org>
List-Subscribe: <mailto:gentoo-commits+subscribe@lists.gentoo.org>
List-Id: Gentoo Linux mail <gentoo-commits.gentoo.org>
X-BeenThere: gentoo-commits@lists.gentoo.org
Content-Transfer-Encoding: quoted-printable
X-Archives-Salt: 3fc73b56-d1c4-412e-973a-cd9090fb856e
X-Archives-Hash: e75493f3fe09446f846c5ad82c1257cb

commit:     27b6a21bd8b4f9372c328b979ee0ba0a8020a2b9
Author:     Zac Medico <zmedico <AT> gentoo <DOT> org>
AuthorDate: Fri Dec  2 01:43:57 2011 +0000
Commit:     Zac Medico <zmedico <AT> gentoo <DOT> org>
CommitDate: Fri Dec  2 01:43:57 2011 +0000
URL:        http://git.overlays.gentoo.org/gitweb/?p=3Dproj/portage.git;a=
=3Dcommit;h=3D27b6a21b

AsynchronousLock: use os.read/write

Similar to commit b432a1b3051d91546649e8f3190675767461d8e8, don't use
unecessary file objects. It also happens that these changes fix
compatibility issues with PyPy.

---
 pym/_emerge/AsynchronousLock.py |   43 +++++++++++++++++++++++++--------=
-----
 1 files changed, 28 insertions(+), 15 deletions(-)

diff --git a/pym/_emerge/AsynchronousLock.py b/pym/_emerge/AsynchronousLo=
ck.py
index be498b8..39e36c8 100644
--- a/pym/_emerge/AsynchronousLock.py
+++ b/pym/_emerge/AsynchronousLock.py
@@ -3,6 +3,7 @@
=20
 import dummy_threading
 import fcntl
+import errno
 import logging
 import sys
=20
@@ -114,12 +115,12 @@ class _LockThread(AbstractPollTask):
 	def _start(self):
 		pr, pw =3D os.pipe()
 		self._files =3D {}
-		self._files['pipe_read'] =3D os.fdopen(pr, 'rb', 0)
-		self._files['pipe_write'] =3D os.fdopen(pw, 'wb', 0)
+		self._files['pipe_read'] =3D pr
+		self._files['pipe_write'] =3D pw
 		for k, f in self._files.items():
-			fcntl.fcntl(f.fileno(), fcntl.F_SETFL,
-				fcntl.fcntl(f.fileno(), fcntl.F_GETFL) | os.O_NONBLOCK)
-		self._reg_id =3D self.scheduler.register(self._files['pipe_read'].file=
no(),
+			fcntl.fcntl(f, fcntl.F_SETFL,
+				fcntl.fcntl(f, fcntl.F_GETFL) | os.O_NONBLOCK)
+		self._reg_id =3D self.scheduler.register(self._files['pipe_read'],
 			PollConstants.POLLIN, self._output_handler)
 		self._registered =3D True
 		threading_mod =3D threading
@@ -130,10 +131,16 @@ class _LockThread(AbstractPollTask):
=20
 	def _run_lock(self):
 		self._lock_obj =3D lockfile(self.path, wantnewlockfile=3DTrue)
-		self._files['pipe_write'].write(b'\0')
+		os.write(self._files['pipe_write'], b'\0')
=20
 	def _output_handler(self, f, event):
-		buf =3D self._read_buf(self._files['pipe_read'], event)
+		buf =3D None
+		if event & PollConstants.POLLIN:
+			try:
+				buf =3D os.read(self._files['pipe_read'], self._bufsize)
+			except IOError as e:
+				if e.errno not in (errno.EAGAIN,):
+					raise
 		if buf:
 			self._unregister()
 			self.returncode =3D os.EX_OK
@@ -171,7 +178,7 @@ class _LockThread(AbstractPollTask):
=20
 		if self._files is not None:
 			for f in self._files.values():
-				f.close()
+				os.close(f)
 			self._files =3D None
=20
 class _LockProcess(AbstractPollTask):
@@ -190,8 +197,8 @@ class _LockProcess(AbstractPollTask):
 		in_pr, in_pw =3D os.pipe()
 		out_pr, out_pw =3D os.pipe()
 		self._files =3D {}
-		self._files['pipe_in'] =3D os.fdopen(in_pr, 'rb', 0)
-		self._files['pipe_out'] =3D os.fdopen(out_pw, 'wb', 0)
+		self._files['pipe_in'] =3D in_pr
+		self._files['pipe_out'] =3D out_pw
 		fcntl.fcntl(in_pr, fcntl.F_SETFL,
 			fcntl.fcntl(in_pr, fcntl.F_GETFL) | os.O_NONBLOCK)
 		self._reg_id =3D self.scheduler.register(in_pr,
@@ -219,7 +226,7 @@ class _LockProcess(AbstractPollTask):
 			except KeyError:
 				pass
 			else:
-				pipe_out.close()
+				os.close(pipe_out)
=20
 		if proc.returncode !=3D os.EX_OK:
 			# Typically, this will happen due to the
@@ -263,7 +270,13 @@ class _LockProcess(AbstractPollTask):
 		return self.returncode
=20
 	def _output_handler(self, f, event):
-		buf =3D self._read_buf(self._files['pipe_in'], event)
+		buf =3D None
+		if event & PollConstants.POLLIN:
+			try:
+				buf =3D os.read(self._files['pipe_in'], self._bufsize)
+			except IOError as e:
+				if e.errno not in (errno.EAGAIN,):
+					raise
 		if buf:
 			self._acquired =3D True
 			self._unregister()
@@ -283,7 +296,7 @@ class _LockProcess(AbstractPollTask):
 			except KeyError:
 				pass
 			else:
-				pipe_in.close()
+				os.close(pipe_in)
=20
 	def unlock(self):
 		if self._proc is None:
@@ -294,8 +307,8 @@ class _LockProcess(AbstractPollTask):
 			raise AssertionError("lock process failed with returncode %s" \
 				% (self.returncode,))
 		self._unlocked =3D True
-		self._files['pipe_out'].write(b'\0')
-		self._files['pipe_out'].close()
+		os.write(self._files['pipe_out'], b'\0')
+		os.close(self._files['pipe_out'])
 		self._files =3D None
 		self._proc.wait()
 		self._proc =3D None