public inbox for gentoo-portage-dev@lists.gentoo.org
 help / color / mirror / Atom feed
* [gentoo-portage-dev] [PATCH] portage.os.waitpid: handle EINTR for bug #525552
@ 2014-12-03  8:54 Zac Medico
  2014-12-03  9:59 ` Alexander Berntsen
  0 siblings, 1 reply; 2+ messages in thread
From: Zac Medico @ 2014-12-03  8:54 UTC (permalink / raw
  To: gentoo-portage-dev; +Cc: Zac Medico

Use a new _eintr_func_wrapper class to wrap waitpid calls and handle
EINTR by calling the function as many times as necessary (until it
returns without raising EINTR).

X-Gentoo-Bug: 525552
X-Gentoo-Bug-url: https://bugs.gentoo.org/show_bug.cgi?id=525552
---
 pym/portage/__init__.py | 24 ++++++++++++++++++++++++
 1 file changed, 24 insertions(+)

diff --git a/pym/portage/__init__.py b/pym/portage/__init__.py
index d8046f3..4ce92f5 100644
--- a/pym/portage/__init__.py
+++ b/pym/portage/__init__.py
@@ -320,12 +320,36 @@ class _unicode_module_wrapper(object):
 			cache[attr] = result
 		return result
 
+class _eintr_func_wrapper(object):
+	"""
+	Wraps a function and handles EINTR by calling the function as
+	many times as necessary (until it returns without raising EINTR).
+	"""
+
+	__slots__ = ('_func',)
+
+	def __init__(self, func):
+		self._func = func
+
+	def __call__(self, *args, **kwargs):
+
+		while True:
+			try:
+				rval = self._func(*args, **kwargs)
+				break
+			except OSError as e:
+				if e.errno != errno.EINTR:
+					raise
+
+		return rval
+
 import os as _os
 _os_overrides = {
 	id(_os.fdopen)        : _os.fdopen,
 	id(_os.popen)         : _os.popen,
 	id(_os.read)          : _os.read,
 	id(_os.system)        : _os.system,
+	id(_os.waitpid)       : _eintr_func_wrapper(_os.waitpid)
 }
 
 
-- 
2.0.4



^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [gentoo-portage-dev] [PATCH] portage.os.waitpid: handle EINTR for bug #525552
  2014-12-03  8:54 [gentoo-portage-dev] [PATCH] portage.os.waitpid: handle EINTR for bug #525552 Zac Medico
@ 2014-12-03  9:59 ` Alexander Berntsen
  0 siblings, 0 replies; 2+ messages in thread
From: Alexander Berntsen @ 2014-12-03  9:59 UTC (permalink / raw
  To: gentoo-portage-dev

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA256

Nice! Go ahead & merge.
- -- 
Alexander
bernalex@gentoo.org
https://secure.plaimi.net/~alexander
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v2
Comment: Using GnuPG with Thunderbird - http://www.enigmail.net/

iF4EAREIAAYFAlR+3v4ACgkQRtClrXBQc7V71gD/Vkbnhco/E7Za0+y3c2X9W2GL
gfoBhhgV3bu2LLNPXSIBAI8Btz9zqJWtKFVS06RI7UlbI9lU5VIIZJtpsrQYhxCh
=pzE5
-----END PGP SIGNATURE-----


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2014-12-03  9:59 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-12-03  8:54 [gentoo-portage-dev] [PATCH] portage.os.waitpid: handle EINTR for bug #525552 Zac Medico
2014-12-03  9:59 ` Alexander Berntsen

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox